Have a look to this code snippet:-
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@"Recieving Data...");
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR with theConenction");
[connection release];
[webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSLog(theXML);
}
I am calling a SOAP web service.There are no errors or warnings displayed in my code.
When I hit the web service through safari it works fine. But the problem arises when I try
hit it through my codes.
Everything works fine but the connection:didRecieveData
does not gets called.
Thus, I get no data in the webData
variable. This webData
is a NSMutableData
object.
The problem seems to be silly but any one with any answers ....
Thank You All.
I suspect you are having a memory management issue. I could be mistaken on this, but I believe that even:
won't work, because
connection
will be released at the end of the containing method, whenconnection
goes out of scope. Make sureNSURLConnection *connection
andNSMutableData *data
are declared as member variables where ever you are doing this, and that youalloc
andinit
them appropriately. My code usually looks like:Also,
release
the connection and data indealloc
. For good measure,release
and set them tonil
at the very end ofdidFailWithError
anddidFinishLoading
:Good luck; I've done this a million times, let me know if you cannot get it working.
You're not getting any error messages in
didFailWithError
either? Kind of a silly suggestion, but are you sure you're setting the properNSURLConnection
delegate?Sometimes it's something small like that.
Another idea is to drop in a toolkit like
ASIHTTPRequest
and see if it works going through them.There also could be problems, if are trying to start NSURLConnection from another Thread. Please call method [connection start] on main thread, if you have not customized Run Loop for it.
You don't happen to be calling the NSConnection in a thread do you? If you are then what's happening is that the thread is terminating before NSConnection and its delegates have finished so it'll just bomb out without an error.
A workaround for this is in this thread