ios - Unable to set content type in AFNetworking AFHTTPRequestOperationManager -


i have web-service requires content-type = application/x-www-form-urlencoded. have set headers not changes can see in request logs. below code , request log

    nsurl *baseurl = [nsurl urlwithstring:@"http://example.net/api/"];      // initialize request operation manager     afhttprequestoperationmanager *manager = [[afhttprequestoperationmanager alloc] initwithbaseurl:baseurl];      // configure request operation manager     [manager setresponseserializer:[afjsonresponseserializer serializer]];     manager.responseserializer.acceptablecontenttypes = [manager.responseserializer.acceptablecontenttypes setbyaddingobject:@"application/x-www-form-urlencoded"];      // send request     [manager get:@"account/register" parameters:params success:^(afhttprequestoperation *operation, id responseobject) {         // process response object         nslog(@"register response: %@",responseobject);     } failure:^(afhttprequestoperation *operation, nserror *error) {         // handle error         nslog(@"register response error: %@",[error description]);     }]; 

but when request, content-type not changed. here request details

    errordomain=afnetworkingerrordomaincode=-1011"request failed: bad request (400)"userinfo=0x109559a40{       afnetworkingoperationfailingurlresponseerrorkey=<nshttpurlresponse: 0x109709260>{         url: http: //example.net/api/account/register       }{         statuscode: 400,         headers{           "cache-control"="no-cache";           "content-length"=142;           "content-type"="application/json; charset=utf-8";           date="mon, 10 mar 2014 14:30:52 gmt";           expires="-1";           pragma="no-cache";server="microsoft-iis/8.0";          "set-cookie"="xxxxx;path=/;domain=example.net, wawebsitesid=xxxxxxx; path=/; httponly";"x-aspnet-version"="4.0.30319";"x-powered-by"="asp.net";         }       },    nslocalizeddescription=requestfailed: badrequest(400),   nserrorfailingurlkey=http: //example.net/api/account/register } 

how can set content-type application/x-www-form-urlencoded?

you don't need set responseserializer manager. please user below code work you.

 nsurl *baseurl = [nsurl urlwithstring:@"http://example.net/api/"];  // initialize request operation manager afhttprequestoperationmanager *manager = [[afhttprequestoperationmanager alloc] initwithbaseurl:baseurl];  // configure request operation manager manager.responseserializer.acceptablecontenttypes = [manager.responseserializer.acceptablecontenttypes setbyaddingobject:@"application/x-www-form-urlencoded"];  // send request [manager get:@"account/register" parameters:params success:^(afhttprequestoperation *operation, id responseobject) {     // process response object     nslog(@"register response: %@",responseobject); } failure:^(afhttprequestoperation *operation, nserror *error) {     // handle error     nslog(@"register response error: %@",[error description]); }]; 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -