ios - Alamofire post 请求返回 "<?xml version="1. 0"encoding="utf- 8"?>"

标签 ios swift asp.net-web-api alamofire

我正在使用 swift 4 向网络 api 发出发布请求。该 API 具有正确的 JSON 数据,但每当我调用它时都会返回以下响应:

<?xml version="1.0" encoding="utf-8"?>

我的代码是:

let urlString = "XXXXXXXXXX/ArticlesByListofIds"
Alamofire.request(urlString, method: .post, parameters: ["ids": "160, 145"],encoding: JSONEncoding.default, headers: nil).responseString { response in
    switch response.result {
        case .success(let responseString1):
            print("the response is: \(responseString1)")
        break

        case .failure(let error):
            print("The error is: \(error)")
    }
}

知道为什么会这样吗?

最佳答案

我看到两件事正在发生。首先,API 似乎使用 XML 而不是 JSON 进行响应,因此您的请求可能不是您想要的。其次,字符编码似乎存在问题。这可以是任何东西;可能是服务器配置错误,也可能是您对文件的解码不正确。

关于ios - Alamofire post 请求返回 "<?xml version="1. 0"encoding="utf- 8"?>",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52091122/

相关文章:

ios - 如何在 Swift 中使用色调和一些文本向 UIImageView 添加叠加层?

xcode - 为什么 UIBarButtonItem 图像总是模糊/模糊/像素化

ios - swift 4 : When a user clicks on a UiButton how do I grab the string that is selected in a UICollectionView?

asp.net-web-api - Ajax 邮政 : 405 Method Not Allowed

asp.net - 向 ASP.NET Web API Controller 发送多部分/混合 http 请求

ios 核心音频 : how to get samples from AudioBuffer with interleaved audio

ios - 根据另一个数组重新排序 NSMutableArray

ios - 这些快速崩溃意味着什么?

c# - POST 和 PUT 的不同模型要求

ios - 将 firebase 数据保存到变量 swift