2013-10-05 2 views
1

수백 개의 위치 지점이 포함 된 문서로 비동기 게시물 요청을 설정하고 있습니다. 이 문서를 내 couchdb에 저장하고 싶습니다."POST"비동기 요청 당 문서 크기 제한이 있습니까?

작은 문서의 경우 요청 응답이 매우 짧은 시간 내에 반환되어 문서를 저장합니다. 문서가 조금 더 커지면 (여전히 < ~ 200k) 응답에 시간이 오래 걸리고 시간 초과가되면 반환됩니다. 시간 제한을 120 초로 설정했습니다.

일부 설정이 누락되었거나 코딩 오류가 있습니까?

- (void)post:(NSData*) requestBody { 
    startTime = [NSDate date]; 
    NSURL* serverURL = [NSURL URLWithString: @"https://myUser:[email protected]/myDB"]; 
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:serverURL]; 
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 
    [request setHTTPMethod:@"POST"]; 
    [request setTimeoutInterval:120.0]; 

    [request setHTTPBody:requestBody]; 


    [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) 
    { 
     if (response != nil) { 
      if ([response respondsToSelector:@selector(statusCode)]) 
      { 
       int statusCode = [((NSHTTPURLResponse *)response) statusCode]; 
       NSLog(@"StatusCode returned was %i", statusCode); 
      } 
      NSLog(@"Response: %@",response); 
     } 

     if ([data length] >0 && error == nil) 
     { 
      NSLog(@"data: %@", data); 
      // DO YOUR WORK HERE 

     } 
     else if ([data length] == 0 && error == nil) 
     { 
      NSLog(@"Nothing was downloaded."); 
     } 
     else if (error != nil){ 
      NSLog(@"Error = %@", error); 
     } 

    }]; 

EDIT : 여전히 시간 초과 문제가 남아 있습니다. didSendBodyData의 진행 상황을 기록하고 바이트가 전송되었음을 인식했습니다. 전부는 아니지만 시간 제한이 발생합니다. 컬 (curl)을 사용하면 업로드가 올바르게 작동합니다.

는 또한 나는 로그에 한 가지를 인식 : 요청이 성공적 총이었고, 예상 바이트가 동일 할 때 :

Total Bytes written: 161120 
Expected Bytes to write: 161120 

When the request failed: 
Total Bytes written: 163840 
Expected Bytes to write: 166839 

다른 아이디어?

- (void)post:(NSData*) requestBody { 
    NSURL* serverURL = [NSURL URLWithString: @"https://mySpace.cloudant.com/myDb"]; 

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:serverURL 
              cachePolicy:NSURLRequestUseProtocolCachePolicy 
             timeoutInterval:30.0]; 
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 
    [request setHTTPMethod:@"POST"]; 
    [request setHTTPBody:requestBody]; 

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
    [connection start]; 
} 

#pragma mark - 
#pragma mark Connection Delegates 
- (void) connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 
{ 
    if ([challenge previousFailureCount] == 0) { 
     NSLog(@"received authentication challenge"); 
     NSURLCredential *newCredential = [NSURLCredential credentialWithUser:@"myUser" 
                    password:@"myPwd" 
                   persistence:NSURLCredentialPersistenceForSession]; 
     NSLog(@"credential created"); 
     [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge]; 
     NSLog(@"responded to authentication challenge"); 
    } 
    else { 
     NSLog(@"previous authentication failure"); 
    } 
} 
+0

iOS보다 서버 구성을 점검하십시오. 제한이 있으면 서버 측에 설정됩니다. –

+0

이 문제를 일으킬 수있는 몇 가지 사항이 있습니다. 난 당신이 어떤 요청 크기 제한 (나는 클라우드의 최대 문서 크기가 64MB와 같은 것 같아요) 타격 의심. 내 첫 번째 조치는 문제를 재현 할 수 있는지 확인하는 것입니다. 컬. 여전히 시간 초과가 발생하면 [email protected]으로 전자 메일을 보내주십시오. 그러면 문제가 해결 될 것입니다. –

답변

0

이것은 URL 형식의 문제인 것으로 보입니다. 낮은 수준의 HTTP 라이브러리를 사용하는 경우 수동으로 기본 인증 헤더를 추가해야합니다. NSURLConnection and Basic HTTP Authentication in iOS에서이를 수행하는 방법을 보여줍니다. 그런 다음 장치가 유효하지 않은 호스트에 연결하려고 시도하기 때문에 시간 초과가 발생할 수 있습니다.

당신은 test.json이 시간 초과 된 JSON을 포함하는 경우 : 즉, 컬 직접 요청을하는데

curl -XPOST https://[email protected]/db -H 'Content-Type:application/json' -d @test.json 

을 시도하여이를 테스트 할 수 있습니다.

curl을 사용하면 디버그가 쉬워지고 (원시 응답을 볼 수 있음) 또한 서버 측 문제인지 또는 라이브러리 특정 사항인지 여부도 확인합니다.

관련 문제