我是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) –