0

我有以下 JSON 用于在服务器上发送请求

{
    "name":"Home",
    "latitude":"45.5037078163837",
    "longitude":"-122.622699737549",
    "radius":"240"
}

请求的 URL 是

  URL: https://api.geoloqi.com/1/place/create 

我提出这样的要求,

    NSString *urlString= @"https://api.geoloqi.com/1/place/create ";
NSURL* url = [[NSURL alloc] initWithString:urlString];
NSString *jsonRequest = @"{\"name\":\"veer\",\"latitude\":\"45.5037078163837\",\"longitude\":\"-122.622699737549\,\"radius\":\"500\ }";

jsonRequest = [self JSONString:jsonRequest];

NSData* requestData = [jsonRequest dataUsingEncoding:NSUTF8StringEncoding];
NSString* requestDataLengthString = [[NSString alloc] initWithFormat:@"%d", [requestData length]];

NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:requestData];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:requestDataLengthString forHTTPHeaderField:@"Content-Length"];
[request setTimeoutInterval:30.0];
[url release];
[requestData release];
[requestDataLengthString release];

NSURLConnection *m_URLConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[request release];

这个请求有什么问题?

4

3 回答 3

3

您的 JSON 字符串似乎在经度和半径值之后缺少 2 个引号:

改变

NSString *jsonRequest = @"{\"name\":\"veer\",\"latitude\":\"45.5037078163837\",\"longitude\":\"-122.622699737549\,\"radius\":\"500\ }";

对此

NSString *jsonRequest = @"{\"name\":\"veer\",\"latitude\":\"45.5037078163837\",\"longitude\":\"-122.622699737549\",\"radius\":\"500\" }";

于 2011-11-23T09:21:29.680 回答
0

从你的问题中不清楚你的问题是什么。

无论如何,你是否也在做:

[m_URLConnection start];

创建连接后?

或者,您可以使用创建连接

[– initWithRequest:delegate:startImmediately:][1]

它允许您指定数据的加载应立即开始。

还可以考虑将[+sendAsynchronousRequest:queue:completionHandler:][2]其用作连接的便利构造函数。

于 2011-11-23T09:19:22.247 回答
0

您尝试访问的 Web 服务 URL 似乎正在使用 SSL。您可能需要将访问令牌放在请求标头中,以便从 Web 服务获得正确的响应。

认证请看链接: https ://developers.geoloqi.com/api/authentication

于 2014-02-14T11:30:59.700 回答