objective c - NSURLConnection not return data -


i have nsurlconnection has been working while , of sudden not working.

for reason, delegate method gets called is:

 -(void)connection:(nsurlconnection *)connection didreceiveresponse: 

none of other delegate methods called. have other classes uses pretty same code, different request , url , seem work fine. have read alot of post talk making sure connection on same thread delegate etc nothing seems work me. know server returning response because if pass same information through simple html form response in browser, , can see evidence server side script running because can see changes making in sql data. , app getting sort of resonse, not getting data or calling connectiondidfinishloading delegate method.

any ideas of problem might be?

here simplified version on code:

#import "registrationviewcontroller.h"  @interface registrationviewcontroller ()  @end  nsmutabledata *responsedata; nsurlconnection *theconnection;  @implementation registrationviewcontroller /*  *  attempt register online. returns false if valiation failed  */ - (bool) registeronline{      // other code here build data request      // url request     nsurl *requesturl = [nsurl urlwithstring:theurl];     nsmutableurlrequest *request = [[nsmutableurlrequest alloc] initwithurl:requesturl];     [request sethttpmethod:@"post"];     [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"];     [request sethttpbody:[nsdata datawithbytes:[bodydata utf8string] length:strlen([bodydata utf8string])]];       // initialse response object     responsedata = [[nsmutabledata alloc] init];      // conection     theconnection = [nsurlconnection connectionwithrequest:request delegate:self];     [theconnection start];      return yes; }  /*  * handle event of registration failing  */ - (void)connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error{     nslog(@"didfailwitherror");      // other code here handle error....  }  -(void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response{     nslog(@"did receive response ");  }  /*  * handle reciept of data  */ - (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data{     nslog(@"didreceivedata");      // add data response     [responsedata appenddata:data];\ }  /*  * data finnished loading  */ -(void)connectiondidfinishloading:(nsurlconnection *)connection {     nslog(@"connectiondidfinishloading");      // other code here handle response.... } 

you should @ response , diagnose what's going on. example, if statuscode not 200, might have problem. see http/1.1 status code definitions.

so, might check statuscode:

- (void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response {     if ([response iskindofclass:[nshttpurlresponse class]]) {         nsinteger statuscode = [(nshttpurlresponse *)response statuscode];          if (statuscode == 200) {             nslog(@"received successful (200) response ");         } else {             nslog(@"whoops, wrong, received status code of %d", statuscode);         }     } else {         nslog(@"not http response");     } } 

you're calling:

theconnection = [nsurlconnection connectionwithrequest:request delegate:self]; 

that starts connection automatically. calling

[theconnection start]; 

you're starting second time. remove start method, or use initwithrequest:delegate:startimmediately: no final parameter.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -