我是Alamofire和Swift的新手,请耐心等待。我正尝试使用Alamofire将产品JSON上传到服务器。但是我不断收到状态码:400失败。有没有办法记录发送到服务器的请求,以便我可以检查我的数据格式是否正确。我在下面提供了上传代码。如何登录HTTP POST请求
static func uploadProduct(productJSON: [String : AnyObject]) {
Alamofire.request(.POST, ServerConfig.ADD_PRODUCT_URL, parameters: productJSON, encoding: .JSON, headers: nil)
.responseJSON(completionHandler: { responseRequest, responseResponse, responseResult in
print(responseRequest!.URL)
print(responseResponse)
print(responseResult)
})
}
这是我得到的错误。
sellers.strawmine.com/api/v1/products/add } { status code: 400, headers {
Connection = "keep-alive";
Date = "Tue, 06 Oct 2015 10:53:44 GMT";
Server = "nginx/1.4.6 (Ubuntu)";
"Transfer-Encoding" = Identity;
} })
FAILURE
请帮忙。我在这方面花了很多时间。提前致谢!
只是一个旁注,为什么不使用iOS自带的本地任务。它非常强大。 –
我还没有听说过这样的事情,请详细说明。 – dashbashrumble
请检查示例[这个问题](http://stackoverflow.com/questions/32953501/cannot-convert-jsonarray-element-to-integer/32954028#32954028)关于发送一个post请求并解析响应json。 [另一个问题](http://stackoverflow.com/questions/32951490/sendsynchronousrequest-is-deprecated-in-ios-9/32951711#32951711),[Another quesiton](http://stackoverflow.com/questions/32786566/sending-custom-http-headers-in-swift/32786812#32786812) –