我想为具有Json正文和需要基本身份验证的头部需求的Api使用Alamofire。当我在Postman中测试通话时,它可以正常工作,但是在AlamoFire中,我收到了服务器错误。如何查看Alamofire请求?
我想看看呼叫这是一个从Alamofire走出去 - 但我似乎无法看到它:(这是我使用的代码)
编辑:
错误低于
[ “错误”:{}, “errorMessages”:< __NSSingleObjectArrayI 0x6000000035c0>(内部服务器错误)]
请求低于
Alamofire.request(endpoint, method: .post, parameters: paramsEncoded, encoding: JSONEncoding.default, headers: headers)
.responseJSON(completionHandler: { (response) in
print(response.request) // This returns just the url eg "http://api.com
print(response.request?.httpBody) // This returns `Optional(85 bytes)`
})
我认为没有被正确创建的请求,但要明白我应该看到的将是有益的。
编辑:这条线从其它问题帮助: NSLog("Request: \(request!.httpMethod!) - \(request!.url!.absoluteString)\n\(request!.httpBody.map { body in String(data: body, encoding: .utf8) ?? "" } ?? "")")
多亏了我已经挂为帮助一个重复的问题。
你能告诉我你的错误吗? –
添加了错误,谢谢 –
您是否尝试打印'response.result.value'? –