I am using web service for my iOS app. I know how to send http post request via URL (not http Body) and get response using NSURLConnection Delegate. But now there is better approach which I am following for web service and passing parameters in request body. I looked for library on google and found this.
But the code is bit difficult for me and I suppose there should be function for the same, which can make this bit easier. Is there any? the code so far is below.
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
initWithURL:[NSURL
URLWithString:**WebService URL**]];
[request setHTTPMethod:@"POST"];
[request setValue:@"text/json" forHTTPHeaderField:@"Content-type"];
NSString *jsonString = [NSString stringWithFormat:@"{\n\"username\":\"%@\",\n\"%@\":\"%@\",\n\"%@\":\"%@\",\n\"%@\":%@,\n\"%@\":%@,\n\"version\":%@,\n\"name\":\"%@\"\n}",userName, @"password",pass,@"accessToken",token,@"isOnline",@"True",@"accountType",type,@"False",name];
[request setHTTPBody:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
jsonString in this code is the http body. I want to pass parameters in request body. Now, after executing this code i get null in NSData variable. whereas my web service function returns a value and also it returns if the execution was successful. what is wrong in my code. Thank you.