Ios Error Domain=com.alamofire.Error.serialization.response Code=-1011“;请求失败:方法不允许(405)";
我正在使用AFNetworking在服务器上下载文件。但它给出了一个405错误。 这是我的代码,我自己的封装方法:Ios Error Domain=com.alamofire.Error.serialization.response Code=-1011“;请求失败:方法不允许(405)";,ios,objective-c,http,afnetworking,Ios,Objective C,Http,Afnetworking,我正在使用AFNetworking在服务器上下载文件。但它给出了一个405错误。 这是我的代码,我自己的封装方法: +(id)download:(NSString *)url progress:(void(^)(CGFloat downloadRate)) downloadProgressBlock completionHandler:(void (^)(NSError *error))completionHandler { NSURL *URL = [NSURL URLWithString:u
+(id)download:(NSString *)url progress:(void(^)(CGFloat downloadRate)) downloadProgressBlock completionHandler:(void (^)(NSError *error))completionHandler {
NSURL *URL = [NSURL URLWithString:url];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDownloadTask *downloadTask = [[self defaultAFManager] downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
downloadProgressBlock(downloadProgress.fractionCompleted);
} destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
return [NSURL fileURLWithPath:filePath];
} completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
completionHandler(error);
}];
[downloadTask resume];
return downloadTask;
}
这是我收到的错误:
Error Domain=com.alamofire.Error.serialization.response Code=-1011“请求失败:不允许方法(405)”UserInfo={NSLocalizedDescription=请求失败:不允许方法(405)
为什么?你能帮个忙吗。也许这个能帮你,也许这个能帮你