ios - NSURLRequest returning nil -



ios - NSURLRequest returning nil -

i performing simple download of info json service. when invoked request returns nil response object. seems same code i've used several times, stumped why request returns nil. have verified generated url valid , homecoming data. missing obvious? thanks!

nsstring *serviceendpoint = [nsstring stringwithformat:@"http://waterservices.usgs.gov/nwis/iv/?sites=%@&period=pt%luh&format=json", guageid, hours]; nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:serviceendpoint]]; nsdata *response = [nsurlconnection sendsynchronousrequest:request returningresponse:nil error:nil]; // response nil @ point nsdictionary *rvdata = [nsjsonserialization jsonobjectwithdata:response options:0 error:&jsonerror];

you're totally disregarding nserror , nsurlresponse populated sendsynchronousrequest method.

first, add together check inquire whether nserror has been populated (if nsurlresponse if nil), , if not nil, should inspect determine problem of request. can take peak nsurlresponse object observe properties help debug problem:

nsmutableurlrequest *request=[nsmutableurlrequest requestwithurl:[nsurl urlwithstring:@"http://waterservices.usgs.gov/nwis/iv/?sites=%@&period=pt%@luh&format=json", guageid, hours]]; [request sethttpmethod:@"get"]; [request setvalue:@"application/json;charset=utf-8" forhttpheaderfield:@"content-type"]; nserror *err; nsurlresponse *response; nsdata *responsedata = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&err]; if (responsedata != nil) { nsdictionary *jsonarray = [nsjsonserialization jsonobjectwithdata:responsedata options: nsjsonreadingmutablecontainers error: &err]; } else { if (error != nil) { nslog(@"error description=%@", [err description]); } }

ios nsdata nsurlrequest

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -