如何使用带有原始json数据请求主体的alamofire快速发出发布请求。以下是原始数据。
{“ KeyValue”:“ {CustomerID':9,Password':test}”}
答案 0 :(得分:0)
在我的项目中,我像下面这样张贴JSON raw data
let userId: String = "jakir"
let userPassword: String = "jakir123"
let js = "{\"userId\":\"\(userId)\",\"userPassword\":\"\(userPassword)\"}"
let parameters: Parameters = ["jsonRequest": "\(js)"]
Alamofire.request("https://abcd.com/login", method: .post, parameters: getParameters(json: js),headers: ApiEndPoint.ProductionServer.headers)
.responseJSON { response in
proccessedResponse(response: response){ json in
completion(json)
}
}
注意:我使用了Alamofire ~> 4.7
答案 1 :(得分:0)
Alamofire.request( url, method: .post , parameters: parameters, encoding: JSONEncoding.default ,headers:nil).responseJSON{
response in
switch response.result {
case .success:
// your code of putting data in form of NSDictionary
self.stopProgress()
}else{
self.stopProgress()
}
case .failure(let error):
print(error)
self.stopProgress()
}
}
// put url in place of url above in parameter.
// progress in SVHUDProgress it's a pod
// you can also use SwiftyJson with it, it would be more helpful for parsing