ios - How to use AFNetwowrking2.0 code for this Example url? -


hi have 1 example url returns json format. when use afnetworking2.0 response url, not getting correct response. here sending code also.

- (void)testhttps {   afsecuritypolicy *securitypolicy = [[afsecuritypolicy alloc] init];   [securitypolicy setallowinvalidcertificates:yes];    afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager]; //manager.responseserializer = [afhttpresponseserializer serializer]; manager.responseserializer = [afjsonresponseserializer serializer];   [manager setsecuritypolicy:securitypolicy];    [manager get:@"xxxxx"      parameters:nil      success:^(afhttprequestoperation *operation, id responseobject) {          nslog(@"json: %@", responseobject);          nsstring* newstr = [[nsstring alloc] initwithdata:responseobject encoding:nsutf8stringencoding];          nsdictionary *dict = [nsjsonserialization jsonobjectwithdata:responseobject options:kniloptions error:nil];      } failure:^(afhttprequestoperation *operation, nserror *error) {          nslog(@"error: %@", error);      }]; } 

i getting json dic nil. , if print "newstr" getting html format response. can please find correct way?

i have done said john getting below result

error: error domain=com.alamofire.error.serialization.response code=-1016 "request failed: unacceptable content-type: text/html" userinfo=0x7ffb39c52ed0 {com.alamofire.serialization.response.error.response= { url: xxxxx } { status code: 200, headers { "cache-control" = "public, max-age=10800"; "content-encoding" = gzip; "content-length" = 2922; "content-type" = "text/html"; date = "wed, 29 apr 2015 06:49:54 gmt"; expires = "wed, 29 apr 2015 09:49:55 gmt"; "last-modified" = "wed, 01 apr 2015 03:19:39 gmt"; server = "ecacc (hhp/9abe)"; vary = "accept-encoding"; "x-cache" = hit; } }, nserrorfailingurlkey=xxxxx, com.alamofire.serialization.response.error.data=<0d0a3c21 444f4354 59504520 68746d6c 20505542 4c494320 222d2f2f 5733432f 2f445444 20584854 4d4c2031 2e302054 72616e73 6974696f 6e616c2f 2f454e22 20226874 74703a2f 2f777777 2e77332e 6f72672f 54522f78 68746d6c 312f4454 442f7868 746d6c31 2d747261 6e736974 696f6e61 6c2e6474 64223e0d 0a3c6874 6d6c2078 6d6c6e73 3d226874 74703a2f 2f777777 2e77332e 6f72672f 31393939 2f786874 6d6c223e 0d0a3c68 6561643e 0d0a3c6d 65746120 68747470 2d657175 69763d22 436f6e74 656e742d 54797065 2220636f 6e74656e >, nslocalizeddescription=request failed: unacceptable content-type: text/html}

the problem you're using afhttpresponseserializer rather afnetworking's afjsonresponseserializer. therefore, when response comes in, parsing http response rather json response. fixed assigning manager.responseserializer afjsonresponseserializer instead:

manager.responseserializer = [afjsonresponseserializer serializer]; 

you'll find won't need create nsdictionary response - upon success should come through nsdictionary object already.

check out afnetworking 2.0 migration guide. it's handy read , make aware of out in future.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -