i want set "application/x-www-form-urlencoded" post method ,i set request.requestserializer.setvalue("application/x-www-form-urlencoded", forhttpheaderfield: "content-type") when set request server content-type not change happen?
this error
{com.alamofire.serialization.response.error.response=<nshttpurlresponse: 0x7c166450> { url: http://test.com } { status code: 404, headers { connection = "keep-alive"; "content-length" = 434; "content-type" = "text/html"; date = "mon, 13 jul 2015 11:18:18 gmt"; server = "nginx/1.0.15"; } }, nserrorfailingurlkey=http://text.com, nslocalizeddescription=request failed: not found (404), this code:
var request = afhttprequestoperationmanager(); request.requestserializer = afhttprequestserializer() request.requestserializer.setvalue("application/x-www-form-urlencoded", forhttpheaderfield: "content-type") request.post(url, parameters: parameters, success: { (oper,obj) -> void in // }) { (oper, error) -> void in // error }
it's error says: server sending webpage (html) 400 status code, when expecting json.
a 400 status code used bad request, generated because you're sending url-form-encoded text application/json. want use afjsonrequestserializer request serializer.
manager.requestserializer = [afjsonrequestserializer serializer]; i not doing code of afnetworking in swift can't tell code of can idea objective-c code.
i hope you.
Comments
Post a Comment