【发布时间】:2020-04-19 22:56:11
【问题描述】:
我正在开发一个 iOS 应用程序,我使用“Alamofire”发出 API 请求,我测试了邮递员的 API(使用 Slim 框架创建),但我无法获得 Alamofire 的邮递员的等效请求。
我尝试 Alamofire 如下:
let parm = ["Password_Father": "test", "Username_Father": "test"]
let headers : HTTPHeaders = ["content-type": "application/json"]
AF.request(URL(string: "http://my.domain.com/page1/login")!,
method: .get, // also try it as post but get error 500 as postman when using post method
parameters:parm,
encoding: JSONEncoding.default,
headers: headers)
.validate(statusCode: 200..<300)
.responseJSON { response in
switch response.result
{
case .success(_) :do {
print("success")
}
case .failure(let error):
print("failure(error)",error)
break
}
}
但我收到此错误failure(error) urlRequestValidationFailed(reason: Alamofire.AFError.URLRequestValidationFailureReason.bodyDataInGETRequest)
我怎样才能得到Alamofire对邮递员的同等要求。
【问题讨论】:
-
可能缺少某些标题?在邮递员中,标签显示
(9),但代码中只有一个? -
stackoverflow.com/questions/60960976/… :您需要联系 API 提供商并请求更改,因为没有运行 Apple 2019 操作系统的设备能够提出这样的请求。
-
@clashsoft 我没有在标头参数中放任何东西,但邮递员放了诸如缓存之类的东西。
-
我来宾说这是
https与http的问题。http需要在 Info.plist 中进行一些配置。
标签: ios swift postman alamofire slim