You need the following request:
NSDictionary *dataDict = @{@"uname": <YOUR_UNAME>};
NSData *postData = [NSJSONSerialization dataWithJSONObject:dataDict options:0 error:nil];
NSMutableURLRequest *request =[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://mypath/index.php?params=123"]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];
[request setValue:[NSString stringWithFormat:@"%d",postData.length] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
To ensure the server have got your data use
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSInteger statusCode = httpResponse.statusCode;
...........
}
In case of success you will get statusCode = 200.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…