Thursday, June 24, 2010

sending lattitude and long to server

// assemble the POST data

NSString *post = [NSString stringWithFormat:@"Latitude=%@&Longitude=%@¬e=%@",
[self urlEncodeValue:latitude],
[self urlEncodeValue:longitude],
[self urlEncodeValue:note],
];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://www.mypositionserver.com/position.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

No comments:

FEEDJIT Live