gpt4 book ai didi

ios - RestKit.ErrorDomain Code=-1011 对 Google 地理编码 API 请求的响应

转载 作者:行者123 更新时间:2023-11-29 10:52:45 25 4
gpt4 key购买 nike

我使用 RESTKit 向 Google 搜索 API 发送一个 HTTP GET:

http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=Sulgen

这个 URL 在与 NSURLRequest 一起使用时工作正常。

RESTKit 将这个字符串转换为

http://maps.googleapis.com/maps/api/geocode/json/?sensor=false&address=Sulgen

提示:在

之前的字符串中插入了一个斜线

我使用 GET 方法来触发请求。这应该如何工作?

编辑:这是导致上述行为的代码:

+ (void)loadGoogleMapsApiLocation_Restkit:(NSString*)searchString
{
/// String definitions
NSString *requestString = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=Frankfurt"];

NSLog(@"requestString: %@",requestString);

/// Create Mappers
RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[GooglePlacemark class]];

[objectMapping addAttributeMappingsFromArray:
@[@"formatted_address"]];

/// setup responseDesriptor
NSString *key_path = @"results";

/// use this new Restkit method instead of the deprecated one
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:objectMapping
method:RKRequestMethodGET
pathPattern:nil
keyPath:key_path
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

/// Create Manager, connect responseDescriptor and execute
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:requestString]];
[manager addResponseDescriptor:responseDescriptor];

[manager getObject:nil
path:@""
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
{
NSLog (@"sucess!");
}

failure:^(RKObjectRequestOperation *operation, NSError *error)
{
NSLog (@"Error: %@", error);
NSLog (@"Response: %@", operation.HTTPRequestOperation.responseString);
}
];
}

错误信息如下:

 I restkit.network:RKObjectRequestOperation.m:150 GET 'http://maps.googleapis.com/maps/api/geocode/json/?sensor=false&address=Frankfurt'

E restkit.network:RKObjectRequestOperation.m:547 Object request failed: Underlying HTTP request operation failed with error: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011 "Expected status code in (200-299), got 404" UserInfo=0xafaff00 {NSLocalizedRecoverySuggestion=<!DOCTYPE html>

404 消息出现是因为 Restkit 将反斜杠插入到请求字符串中。如果在浏览器或 rest 客户端中触发,原始字符串请求可以正常工作。

感谢任何帮助。

最佳答案

您需要重新组织您的基本 URL 和路径:

NSString *baseURLString = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode"];

NSString *requestPath = @"json";

NSDictionary *parameters = @{@"sensor":@"false",@"address":@"Frankfurt"};

RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:baseURLString]];

[manager getObject:nil
path:requestPath
parameters:parameters
...

关于ios - RestKit.ErrorDomain Code=-1011 对 Google 地理编码 API 请求的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19755632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com