好的,所以我的iOS应用需要发送Latitude&通过HTTP POST
方法接收郊区的经度。
这是我获取Lat& amp; amp; amp;经度
float lat = locationManager.location.coordinate.latitude;
float lon = locationManager.location.coordinate.longitude;
我想用这样的HTTP POST方法发送它
here is the problem
NSString *post = @"key1=val1&key2=val2";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://www.nowhere.com/sendFormHere.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
我想知道的是,我是否可以将float
部分更改为字符串或类似于HTTP POST
方法中使用的内容
答案 0 :(得分:1)
您可以创建帖子:
NSString *post = [NSString stringWithFormat:@"lat=%f&lon=%f", lat, lon];
答案 1 :(得分:0)
当然,你可以在身体中添加浮动:
NSString *post = [NSString stringWithFormat:@"lat=%f,long%f",lat,lon];