Re: NSURLConnection problem on Mac OS X 10.7
Re: NSURLConnection problem on Mac OS X 10.7
- Subject: Re: NSURLConnection problem on Mac OS X 10.7
- From: Mike Abdullah <email@hidden>
- Date: Thu, 08 Sep 2011 10:46:35 +0100
On 7 Sep 2011, at 14:37, Payal Mundhada wrote:
> Hi Mike,
>
> I am creating request as follows:
>
> @implementation WebService
> -(void)makeRequest
> {
> m_URLRequest= [NSMutableURLRequest requestWithURL:url];
> [m_URLRequest setHTTPMethod:@"POST"];
> [m_URLRequest addValue:SOAPACTION_ISSERVICEAVAILABLE forHTTPHeaderField:@"SOAPAction"];
> [m_URLRequest addValue:CONTENTTYPE forHTTPHeaderField:@"Content-Type"];
> [m_URLRequest setHTTPBody:[REQUEST_ISSERVICEAVAILABLE dataUsingEncoding:NSUTF8StringEncoding]];
>
> m_connection =[[NSURLConnection alloc]initWithRequest:m_URLRequest delegate:self];
>
> m_runLoop =[NSRunLoop currentRunLoop];
> m_runLoopRef =[m_runLoop getCFRunLoop];
> if(m_connection!=nil)
> {
> m_receivedData=[[NSMutableData data] retain];
> CFRunLoopRun();
> }
> }
>
> In delegate connectionDidFinishLoading handling as follows:
> -(void)connectionDidFinishLoading:(NSURLConnection *)connection
> {
> @try {
> CFRunLoopStop(m_runLoopRef);
> [m_connection release];
> m_connection =nil;
> }
> }
> -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
> {
> [m_receivedData setLength:0];
> NSHTTPURLResponse *urlResponse=(NSHTTPURLResponse*)response;
> NSString *str_response=[NSHTTPURLResponse localizedStringForStatusCode:[urlResponse statusCode]];
>
> NSLog(@"%@", str_response);
>
> NSLog(@"%@", [urlResponse allHeaderFields]);
> if([urlResponse statusCode]> 200)
> {
> [m_receivedData release];
> m_receivedData =nil;
> NSLog(@"%@",str_response);
> }
> }
> @end
What made you decide to write this code in the first place? NSURLConnections are intended to be asynchronous. You're trying to force it to be synchronous in a way that I suspect Cocoa doesn't expect.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden