【发布时间】:2015-08-25 15:08:41
【问题描述】:
我正在调用 REST 服务来发布 lat & lng,但是数据没有发送到服务器
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *crnLoc = [locations lastObject];
self.locationDesc.text = [NSString stringWithFormat:@"%@",crnLoc.description];
NSLog(@"%@",crnLoc.description);
NSURL *aUrl = [NSURL URLWithString:@"http://localhost/web/location/create.php?"];
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:aUrl];
NSString *params = [[NSString alloc] initWithFormat:@"latitude=%g&longitude=%g", crnLoc.coordinate.latitude, crnLoc.coordinate.longitude];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
NSLog(@"%@",request.URL);
}
我在上面的代码中做错了什么吗?我可以使用 REST Easy 客户端(firefox 插件)发布数据。
【问题讨论】:
-
参数是什么,你在哪里追加?
-
>> 参数为@"latitude=%g&longitude=%g", .... at * param 并在 [request setHTTPBody:[params.....
-
我想将 lat & lng 传递给 web 服务,以便最终的 url 是 - localhost/web/location/… 但不知何故 url 没有得到构造
-
如果您希望它们出现在 URL 中,您需要将它们添加到该位置。现在你正在将它们放入体内。或者如果它确实是一个 post 请求,数据应该放在正文中,服务应该从正文中获取数据。
标签: ios web-services rest