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 g开发者_JS百科et 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.
As I commented earlier;
in your first line it says "%verifyLogin.json". Shouldn't that be; "%@verifyLogin.json" ????
For me I forgot to add http:// as i was testing locally. But after adding http it ran successfully
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!
精彩评论