ios - 我得到一个空字节数组作为 API 调用的结果,预计将返回一个 png 图像
问题描述
我正在使用 Alamofire 进行网络呼叫。预计会返回一个 png 图像。但是从 iOS 应用程序我无法获取图像,http 响应成功但得到一个空字节数组。我尝试过使用 Postman,从那里我可以看到图像作为响应。以下是我的代码片段。
var imageParams: [String: Any] = [:]
imageParams["pois"] = ["start,-37.811581918854074,144.9472252859507","stop,-37.821561918854074,145.9472252859507", "stop,-37.711581918854074,144.9472252859507","stop,-37.751581918854074,144.9472252859507", "end,-37.941581918854074,144.9472252859507"]
Alamofire.request("http://192.168.43.210:8086/v1/location/getHsMapImage",
method: .post,
parameters: imageParams,
encoding: URLEncoding.httpBody,
headers: ["Content-Type": "application/json"]).responseString { (response) in
switch(response.result) {
case .success(_):
if let data = response.result.value{
print(response.result.value)
}
break
case .failure(_):
print(response.result.error)
break
}
}
解决方案
推荐阅读
- ios - cocoapod 如何处理传递依赖
- java - System.out.println 它没有显示在终端中
- bash - 将管道中单个命令的标准错误分配给 Bash 中的变量
- logging - 如何使用 logback API 在 logback 配置中添加或删除记录器
- c# - dotnet SSL 问题
- regex - 使用 Stanza 提取日期时间短语
- linux - 如何在 Git 标签中实现分页
- angular - 带有来自枚举的queryParams键的角度路由器链接
- node.js - 错误代码 nodejs : unhandledpromiserejectionwarning
- python - 继承是否适用于静态变量