views:

1151

answers:

3

Hi

I am using the ASIHTTPRequest class in order to communicate with a web service and get a response. This is how I send a request to the server

NSString *str = [NSString stringWithFormat:@"%@verifyLogin.json", serverUrl];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[request addRequestHeader:@"Content-Type" value:@"text/x-gwt-rpc; charset=utf-8"];
NSDictionary* data = [NSDictionary dictionaryWithObjectsAndKeys:emailId, @"username", pwd, @"password", nil];
[request appendPostData: [[data JSONFragment] dataUsingEncoding: NSUTF8StringEncoding]];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request setDidFinishSelector: @selector(gotLoginResponse:)];
[request setDidFailSelector: @selector(loginRequestFailed:)];

[networkQueue addOperation: request];
[networkQueue go];

The control immediately goes to the error routine and the error description and domain are

Unable to start HTTP connection and ASIHTTPRequestErrorDomain

I can get the same request to work via a desktop tool for checking HTTP requests so I know the settings are all correct.

Can someone please tell me what I am missing here while sending the request?

Thanks.

+1  A: 

As I commented earlier;

in your first line it says "%verifyLogin.json". Shouldn't that be; "%@verifyLogin.json" ????

MiRAGe
Sorry that was a typo. Will correct in the question
lostInTransit
A: 

I'm having the same problem with putting hundreds of asychronous requests into a NSOperationQueue as described on the ASIHTTPRequest website. I'm trying to download images, and 9 out of 10 requests fail with: Error Domain=ASIHTTPRequestErrorDomain Code=6 UserInfo=0x8b53f40 "Unable to start HTTP connection"

Very few of the requests work though..

This is confusing, since it says on http://allseeing-i.com/ASIHTTPRequest/How-to-use#using_a_queue

"If you add more requests than the queue's maxConcurrentOperationCount property, requests will wait for others to finish before they start."

Any ideas?

@Jasconius: Can you elaborate what you mean by "setting that particular request to not attempt to use a persistent connection"?Do you mean clear a currently stored session cookie?([ASIHTTPRequest clearSession])
A: 

Can you check the status code of the request when it fails? I recently dealt with a JSON user authentication issue with ASI-HTTP-Request where the first request would always fail with Status Code 0 and some sort of underlying network connection failure (as if it wasn't connected to the internet, but clearly was).

I was able to solve it by setting that particular request to not attempt to use a persistent connection.

So try that first!

Jasconius