首页 > 解决方案 > 我得到一个空字节数组作为 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

                            }
        }

标签: iosswiftalamofire

解决方案


推荐阅读