수백 개의 위치 지점이 포함 된 문서로 비동기 게시물 요청을 설정하고 있습니다. 이 문서를 내 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");
}
}
iOS보다 서버 구성을 점검하십시오. 제한이 있으면 서버 측에 설정됩니다. –
이 문제를 일으킬 수있는 몇 가지 사항이 있습니다. 난 당신이 어떤 요청 크기 제한 (나는 클라우드의 최대 문서 크기가 64MB와 같은 것 같아요) 타격 의심. 내 첫 번째 조치는 문제를 재현 할 수 있는지 확인하는 것입니다. 컬. 여전히 시간 초과가 발생하면 [email protected]으로 전자 메일을 보내주십시오. 그러면 문제가 해결 될 것입니다. –