2013-11-04 2 views
0

AFNetworking에서 요청을 보내려고하지만 요청이 양호하더라도 "네트워크 연결이 끊어졌습니다."라는 문제가 발생합니다. 클라이언트와 요청을 보내려고하고 있는데 적절한 응답을 얻고 있습니다. AFNetworking에서 네트워크 연결 문제가 발생했습니다.

요청의 세부

은 다음과 같습니다 URL : https://www.ez-point.com/search 방법 : 인증 헤더 GET : xxxxxxxxxxxxxxx입니다 요청 페이로드 : "SEARCH_TEXT": "값"여기

내가 사용하고 코드입니다 :

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월 4일 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] : 오류 도메인 = NSURLErrorDomain 코드 = -1005 "네트워크 연결이 끊어졌습니다." 사용자 정보 = 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에 GET하고 있어요 매개 변수, 권한 부여와 함께 : XXXXXX 및 요청 페이로드 SEARCH_TEXT로 : UJO526

Rest Client used

답변

1

AFHTTPClient *client=[[AFHTTPClient alloc]initWithBaseURL:[NSURL URLWithString:@"https://www.ez-point.com/search"]]; 

    [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES]; 
    [client registerHTTPOperationClass:[AFJSONRequestOperation class]]; 

    [client setDefaultHeader:@"Authorization" value:@"xxxxxxx"]; 
    [client setDefaultHeader:@"Content-type" value:@"application/json"]; 
    [client setDefaultHeader:@"Accept" value:@"application/json"]; 

    NSMutableDictionary *jsonDic = [[NSMutableDictionary alloc]initWithCapacity:1]; 
    [jsonDic setValue:@"UJO526" forKey:@"search_text" ]; 


    [client getPath:@"" parameters:jsonDic success:^(AFHTTPRequestOperation *operation, id responseObject) 
    { 
     NSArray *searchResults = (NSArray *) responseObject; 
     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:^(AFHTTPRequestOperation *operation, NSError *error) { 

    }]; 
+0

으로 시도 이 오류가 발생합니다. 2013-11-04 15 : 39 : 52.517 EZ-POINT [4489 : c07] E restkit.network:RKObjectRequestOperation.m:209 'https : //www.ez-point. com/search /? search_text = UJO526 ' – Noor

+0

URL 끝 부분에 추가 텍스트가 추가되어 404 오류가 반환됩니다. – Noor

+0

이것이 get 메소드인지 확인 하시겠습니까? –

관련 문제