我已经在我的项目中集成了 AFNetworking 。但是当我使用 AFNetworking 收到请求时,它总是会进入失败块。下面是我的代码。请让我知道,我在这里做错了什么?
NSString *baseUrl = @"http://www.nactem.ac.uk/software/acromine/dictionary.py?sf=ETA";
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:baseUrl parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"%@",responseObject);
//Always it invoke the Failure block
}failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSHTTPURLResponse *response = error.userInfo[AFNetworkingOperationFailingURLResponseErrorKey];
NSInteger statusCode = response.statusCode;
NSLog(@"Error Code=%ld",statusCode);
NSLog(@"Desc=%@",response.description);
}];
注意:- 这是有效的 URL。 http://www.nactem.ac.uk/software/acromine/dictionary.py?sf=ETA
以下是错误代码和描述:-
Error Code 200
Error Description <NSHTTPURLResponse: 0x7fbab8509860> { URL: http://www.nactem.ac.uk/software/acromine/dictionary.py?sb=hmm } { status code: 200, headers {
Connection = close;
"Content-Type" = "text/plain; charset=UTF-8";
Date = "Wed, 20 Apr 2016 00:17:27 GMT";
Server = "Apache/2.2.15 (Scientific Linux)";
"Transfer-Encoding" = Identity;
} }