3

AFNetworking을 사용하여 웹 서버에 다중 파트 양식을 보내고 있습니다. 내 AFHTTPRequestOperation에 문제가 있습니다. 그것은 성공이고 실패한 블록은 내가 시작한 후에 결코 호출되지 않습니다.AFNetworking AFHTTPRequestOperation 블록이 호출되지 않습니다.

여기 내 코드 (그것의 이력서)

NSMutableURLRequest *request = [[ServerAPI sharedClient] multipartFormRequestWithMethod:@"POST" path:postUrl parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData> formData) { 
     [formData appendPartWithFileData:picture.picture_data name:@"InputFile" fileName:picture.name mimeType:@"image/jpg"]; 
    }]; 

    AFHTTPRequestOperation *operation = [[ServerAPI sharedClient] HTTPRequestOperationWithRequest: request success:^(AFHTTPRequestOperation *operation, id responseObject) { 
     NSLog(@"Success"); 
    } failure: ^(AFHTTPRequestOperation *operation, NSError *error) { 
     NSLog(@"Failure"); 
    }]; 

    [operation setUploadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) { 
     NSLog(@"%f", (totalBytesRead/(float) totalBytesExpectedToRead)); 
    }];   
    [[ServerAPI sharedClient] enqueueHTTPRequestOperation:operation]; 

나는 진보의 로그를 볼 수 있지만 성공과 실패 블록이 호출되지 않습니다.

picture.picture_dataUIImageJPEGRepresentation(image, 0.7) ServerAPI로 초기화 NSDataAFHTTPClient의 서브이며 sharedCliend은 단일 방법이다.

AFNetworking의 이유는 적절한 오류 메시지가 아니라도 내 블록을 호출하지 않기 때문입니다.

감사합니다.

편집 난 그냥이 일하기 전에 동일한 URL에 GET 요청을 수행하며 평소와 같이 작동합니다. 내가 사용하고있는 URL은 다음과 같습니다 : part/_layouts/UploadEx.aspx?List=%7BD432BF97-7175-40C1-8E0D-27D8661CBC90%7D&RootFolder=%2Fpwa%2Fpart%2FLibrary&Source=http%3A%2F%2Fwww%2Emysite%2Ecom%2Fpwa%2Fpart%2FLibrary%2FForms%2FAllItems%2Easpx&IsDlg=1

+1

문제점을 찾을 수 있습니까? – jsetting32

답변

0

코드에 postUrl을 확인하십시오. BaseURL+postURL이 유효해야합니다. URL이 BaseURL+postURL 인 일반 웹 브라우저를 사용하여 이미지를 업로드 해보십시오. 파일 업로드를 위해 작동하지만 JSON/HTML 페칭 작동하지 않습니다 HTTPRequestOperationWithRequest:success:failure:

편집

방법. 사용해보기

AFHTTPRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request]; 

[operation setUploadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) { 
     NSLog(@"%f", (totalBytesRead/(float) totalBytesExpectedToRead)); 
    }]; 

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 
     NSLog(@"Success"); 
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
     NSLog(@"Failure"); 
    }]; 

[[ServerAPI sharedClient] enqueueHTTPRequestOperation:operation]; 
+0

나는 그것의 바로 전에 동일한 URL을 가지고 요청을한다, 그것은 평소와 같이 일한다 ... 나는 질문에 사용하고있는 URL을 게시 할 것이다, 고마워! –

+0

서버에 업로드 된 파일 크기에 대한 제한 사항이 있습니까? –

+0

나는 대답을 편집한다. 도움이 되었으면 –

관련 문제