Json response is successful in browser but displays error message in simulator
<p>I have a server which sends JSON web response using the browser. However when the same URL is passed through the simulator throws an error message.
The code is as below:</p>

<pre><code>NSString *postString = [NSString stringWithFormat:@"username=\"tango\"&amp;password=\"charlie\""];

NSLog(@"%@",postString);
//encode post string in supported encoding format in post data
postData = [postString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

if(connection)
  return YES;
else 
  return NO;

[NSMutableRequest setHTTPRequest:urlString];
</code></pre>

<p>The header part is as follows:</p>

<pre><code>[request setURL:url];

//set HTTP method Post
[request setHTTPMethod:@"POST"];

//set HTTP header field with length of post data
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];

//set encoding value for HTTP header field
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

 //set HTTP body or url request with postData
 [request setHTTPBody:postData];
</code></pre>

<p>I expected a successful log message but the simulator shows an invalid username and password log.</p>

<p>What could be the reason?</p>