I do not know the details of your web service, but the code below may be the source of your problem (or at least one of them!)
[request setValue:jsonString forHTTPHeaderField:@"json"]; responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&theError]; [request setHTTPBody:responseData];
You submit a request before setting the body, which I assume should contain your jsonString content. Also, you assign your jsonString in the header field, are you sure you want to? Here guess what might work:
[request setValue:@"application/json" forHTTPHeaderField:@"Content-type"]; [request setHTTPBody:jsonString]; responseData =
I suggest you look at this code well, as this is a mess at the moment! You have two NSURLConnection , one asynchronous and one synchronous , it's hard to understand what / why you are doing all this, so check the Apple documentation for NSURLConnection and arrange the code ...
[EDIT]
Here is my suggestion for you:
NSError *theError = nil; NSArray *keys = [NSArray arrayWithObjects:@"UserId", @"Password", nil]; NSArray *objects = [NSArray arrayWithObjects:@"rajin.sasi", @"abhi1551", nil]; NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; NSString *jsonString = [jsonDictionary JSONRepresentation]; NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.0.83:8082/WebServiceProject/AcessWebservice?operation=login"]]; [request setValue:jsonString forHTTPHeaderField:@"json"]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:jsonData]; NSURLResponse *theResponse =[[NSURLResponse alloc]init]; NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&theError]; NSMutableString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSDictionary *jsonDictionaryResponse = [string JSONValue]; [string release]; [theResponse release];
Rog
source share