Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

shweta13

macrumors member
Original poster
Aug 7, 2008
38
0
Hi,

I want to send a HTTP synchronous request.
I tried using sendSynchronousRequset of NSURLConnection but I am facing exceptions and leaks.

Can anyone please suggest me any way to send synchronous request??

Thanks,
Shweta
 

shweta13

macrumors member
Original poster
Aug 7, 2008
38
0
Post the code you are using, the exact exceptions and details of the leaks.



NSError** pError;
NSData* m_pRecData;
NSURL *pUrl = [NSURL URLWithString:mad:"http://www.apple.com"];
NSURLRequest* pRequest = [NSURLRequest requestWithURL:pUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLResponse* pResponse = [[NSURLResponse alloc] initWithURL:pUrl MIMEType:mad:"RFC 2822" expectedContentLength:100 textEncodingName:mad:"name"];
m_pRecData = [[NSURLConnection alloc] sendSynchronousRequest:pRequest returningResponse:&pResponse error:pError];







*** -[NSURLConnection sendSynchronousRequest:returningResponse:error:]: unrecognized selector sent to instance 0x407cc0
(gdb) continue
2008-09-15 16:09:55.413 myhttp[929:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURLConnection sendSynchronousRequest:returningResponse:error:]: unrecognized selector sent to instance
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Please use the code BB tags as that's unreadable...

Edit: like this:

Code:
        NSError** pError;
	NSData* m_pRecData;
	NSURL *pUrl = [NSURL URLWithString:@"http://www.apple.com"];
	NSURLRequest* pRequest = [NSURLRequest requestWithURL:pUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
	NSURLResponse* pResponse = [[NSURLResponse alloc] initWithURL:pUrl MIMEType:@"RFC 2822" expectedContentLength:100 textEncodingName:@"name"];
	m_pRecData = [[NSURLConnection alloc] sendSynchronousRequest:pRequest returningResponse:&pResponse error:pError];

Edit again your list like makes no sense whatsoever. You have allocated an instance of NSURLConnection but not initalised it. This will cause massive failures. You then send a class method to this instance. This will not work (which is why you get the unrecognized selector error). I think you need to look at the basic Cocoa documentation and understand the difference between a class and an instance method.

Your last like should read

Code:
m_pRecData = [NSURLConnection sendSynchronousRequest:pRequest returningResponse:&pResponse error:pError];
 

shweta13

macrumors member
Original poster
Aug 7, 2008
38
0
Please use the code BB tags as that's unreadable...

Edit: like this:



Edit again your list like makes no sense whatsoever. You have allocated an instance of NSURLConnection but not initalised it. This will cause massive failures. You then send a class method to this instance. This will not work (which is why you get the unrecognized selector error). I think you need to look at the basic Cocoa documentation and understand the difference between a class and an instance method.

Your last like should read

Code:
m_pRecData = [NSURLConnection sendSynchronousRequest:pRequest returningResponse:&pResponse error:pError];



Thanks a lot ...that was of great help...I now know where I went wrong..
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.