我正在尝试使用 AFNetworking 发送请求,但我遇到了“网络连接丢失”的问题,尽管请求很好。我正在尝试向客户端发送请求,并且得到了正确的响应。
请求的详细信息是: URL:https ://www.ez-point.com/search 方法:GET 授权头:xxxxxxxxxxxxxxx 请求负载:“search_text”:“value”
这是我正在使用的代码:
NSURL *url = [[NSURL alloc] initWithString:@"https://www.ez-point.com/search"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setValue:@"xxxxxxx" forHTTPHeaderField:@"Authorization" ];
[request setHTTPMethod:@"GET"];
NSMutableDictionary *jsonDic = [[NSMutableDictionary alloc]init];
[jsonDic setValue:@"UJO526" forKey:@"search_text" ];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDic options:NSJSONWritingPrettyPrinted error:nil];
[request setHTTPBody:jsonData];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSArray *searchResults = JSON;
if ([searchResults count] == 1){
id result = [searchResults objectAtIndex:0];
double latitude = [[result valueForKey:@"latitude"] doubleValue];
double longitude = [[result valueForKey:@"longitude"] doubleValue];
NSString *ezPoint = [result valueForKey:@"value"];
NSString *tags = [result valueForKey:@"tags"];
[self setAnnotation:latitude ForLongitude:longitude withEZPoint:ezPoint WithTags:tags];
}
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
}
];
[operation start];
我得到的错误是:
2013-11-04 15:01:05.143 EZ-POINT[4074:c07] E restkit.network:RKObjectRequestOperation.m:209 GET ' https://www.ez-point.com/search ' (0) [2.8806 s ]: Error Domain=NSURLErrorDomain Code=-1005 "网络连接丢失。" UserInfo=0x88b5c30 {NSErrorFailingURLStringKey= https://www.ez-point.com/search , NSErrorFailingURLKey= https://www.ez-point.com/search , NSLocalizedDescription=网络连接丢失。, NSUnderlyingError=0x1bc83790 "的网络连接丢失。"}
在 REST 客户端中,我在https://www.ez-point.com/search上使用参数 Authorization:xxxxxx 和 Request Payload search_text: UJO526 进行 GET