내 앱에서 서버로 비디오 파일을 업로드해야합니다. 나는 [AFHTTPRequestOperationManager post:parameters:success:failure]
을 통해 그렇게 시도했지만 불행히도 요청 시간 초과가 계속 발생했습니다. 지금은 업로드 작업 만들기와 비슷한 것을 시도하고 있습니다.은 the AF Docs입니다. AFNetworking 자격 증명을 사용하여 업로드 작업 (HTTP Basic Auth)
setSessionDidReceiveAuthenticationChallengeBlock:
on SO과
AF Docs을 읽고 다음과 같이 전체 업로드 malarky을 구현하기 위해 노력 :
__block ApiManager *myself = self;
// Construct the URL
NSString *strUrl = [NSString stringWithFormat:@"%@/%@", defaultUrl, [self getPathForEndpoint:endpoint]];
NSURL *URL = [NSURL URLWithString:strUrl];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[request setHTTPMethod:@"POST"];
// Build a session manager
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
// Set authentication handler
[manager setSessionDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition(NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential *__autoreleasing *credential) {
*credential = myself.credentials;
return NSURLSessionAuthChallengeUseCredential;
}];
// Create the upload task
NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithRequest:request fromFile:filePath progress:nil completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error) {
[myself endpoint:endpoint returnedFailure:error];
} else {
[myself endpoint:endpoint returnedSuccess:responseObject];
}
}];
// and run with it
[uploadTask resume];
myself.credentials
객체가 올바른 사용자 이름과 암호를 가지고 이전에 설정되었습니다. 이 요청이 발생할 때마다 401 unauthorised
을 응답으로받습니다. 위의 챌린지 블록에 NSLog(@"CHALLENGE")
을 넣으려고 시도했지만 결코 호출되지 않는 것 같습니다. 그래서 AFNetworking은 나에게 자격 증명을 제공하는 방법을 제공하지 않습니다. 저는 이것이 Postman과 테스트를했기 때문에 이것이 서버 측에서 완벽하게 작동한다는 것을 압니다.
이 업로드 작업으로 HTTP 기본 인증에 대한 자격 증명을 제공하도록 AFNetworking을 어떻게받을 수 있습니까?