lostInTransit
lostInTransit

Reputation: 70997

iPhone and ASIHTTPRequest - Unable to start HTTP connection

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.

Upvotes: 5

Views: 8714

Answers (3)

Rupesh
Rupesh

Reputation: 2051

For me I forgot to add http:// as i was testing locally. But after adding http it ran successfully

Upvotes: 2

M. Ryan
M. Ryan

Reputation: 7192

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!

Upvotes: 0

Jake
Jake

Reputation: 3973

As I commented earlier;

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

Upvotes: 5

Related Questions