I cannot figure out how to send this data to server. I can't find out what's wrong in my code.
This the api documentation:
.
I sent it in postman as form:
This my JSON I sent with my request:
{
"return_data":{
"telephone":"0123456789",
"date_ordered":"2018-11-26 10:58:51",
"model":"طوق نجاة",
"order_id":"130",
"lastname":"fares",
"firstname":"fares1",
"product":"130",
"quantity":"1",
"opened":"0",
"comment":"",
"email":"fareselsokary456@gmail.com",
"return_reason_id":"2"
}
}
And this is my code. It sent the request but it gets an error from the server:
func PostReturnReasons(firstName : String, lastName : String, phone : String, email : String,order_id : String,date_orderd : String,product : String,model : String,quantity : String,return_reason_id : String,opened : String,comment : String, complition : @escaping COMplitionHandler){
let body : [String : Any] = [
"firstname" : firstName,
"lastname" : lastName,
"email" : email,
"telephone" : phone,
"order_id" : order_id,
"date_ordered" : date_orderd,
"product" : product,
"model" : model,
"quantity" : quantity,
"return_reason_id" : return_reason_id,
"opened" : opened,
"comment" : comment
]
Alamofire.request("http://brook1.com/api/productreturn/key/12345", method: .post, parameters: ["return_data" : body], encoding: JSONEncoding.default).responseString { (response) in
print(NSString(data: (response.request?.httpBody)!, encoding: String.Encoding.utf8.rawValue)!)
if response.result.error == nil{
let json = try! JSON(data: response.data!)
print(json)
complition(true)
}else{
complition(false)
debugPrint(response.result.error as Any)
}
}
}
Comments
Post a Comment