ios - Why AFNetworking always go into Failure block? -
i have integrated afnetworking here in project. when request using afnetworking, go failure block. below code. please let me know, doing wrong here?
nsstring *baseurl = @"http://www.nactem.ac.uk/software/acromine/dictionary.py?sf=eta"; afhttpsessionmanager *manager = [afhttpsessionmanager manager]; [manager get:baseurl parameters:nil progress:^(nsprogress * _nonnull downloadprogress) { } success:^(nsurlsessiondatatask * _nonnull task, id _nullable responseobject) { nslog(@"%@",responseobject); //always invoke failure block }failure:^(nsurlsessiondatatask * _nullable task, nserror * _nonnull error) { nshttpurlresponse *response = error.userinfo[afnetworkingoperationfailingurlresponseerrorkey]; nsinteger statuscode = response.statuscode; nslog(@"error code=%ld",statuscode); nslog(@"desc=%@",response.description); }];
note:- valid url. http://www.nactem.ac.uk/software/acromine/dictionary.py?sf=eta
also below error code , description:-
error code 200 error description <nshttpurlresponse: 0x7fbab8509860> { url: http://www.nactem.ac.uk/software/acromine/dictionary.py?sb=hmm } { status code: 200, headers { connection = close; "content-type" = "text/plain; charset=utf-8"; date = "wed, 20 apr 2016 00:17:27 gmt"; server = "apache/2.2.15 (scientific linux)"; "transfer-encoding" = identity; } }
i found answer :-
nsstring *url = @"http://www.nactem.ac.uk/software/acromine/dictionary.py?sf=hmm"; afhttpsessionmanager *manager = [afhttpsessionmanager manager]; //missing line (any request or response serializer dealing http encouraged subclass) manager.responseserializer = [afhttpresponseserializer serializer]; [manager get:url parameters:nil progress:nil success:^(nsurlsessiondatatask * _nonnull task, id _nullable responseobject) { nserror* error; nsdictionary* json = [nsjsonserialization jsonobjectwithdata:responseobject options:kniloptions error:&error]; nslog(@"success= %@",json); }failure:^(nsurlsessiondatatask * _nullable task, nserror * _nonnull error) { nshttpurlresponse *response = error.userinfo[afnetworkingoperationfailingurlresponseerrorkey]; nsinteger statuscode = response.statuscode; nslog(@"fail=%ld",statuscode); }];
Comments
Post a Comment