Ich habe AFNetworking von here in meinem Projekt integriert. Aber wenn ich eine Anfrage mit AFNetworking bekomme, geht es immer in den Failure-Block. Unten ist mein Code. Bitte lass mich wissen, was ich hier falsch mache?Warum AFNetworking immer in Fehlerblock gehen?
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);
}];
Hinweis: - Dies ist die gültige URL. http://www.nactem.ac.uk/software/acromine/dictionary.py?sf=ETA
Auch unten ist der Fehlercode und Beschreibung: -
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;
} }
Haben Sie App Transportsicherheit hinzufügen http-Verbindung in Ihrem plist zu ermöglichen? –
Ja, ich habe –
hinzugefügt. Was ist der Fehler, den Sie im Fehlerblock bekommen? – CrimsonChris