AFNetworking 2.0: NSLocalizedDescription=Fehler bei der Anfrage: inakzeptabel content-type: text/html -

Versuchte ich BEKOMMEN html-von Apple-homepage.

AFHTTPRequestOperationManager *manager
= [AFHTTPRequestOperationManager manager];
[manager GET:@"http://www.apple.com/jp" parameters:nil
     success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"HTML: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

Diese fehlgeschlagen mit Fehler Meldung wie unten:

2014-02-07 14:54:22.922 Tests[1833:70b] Error: Error Domain=AFNetworkingErrorDomain Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo=0x8a32650 {NSErrorFailingURLKey=http://www.apple.com/jp/, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xea2e1a0> { URL: http://www.apple.com/jp/} { status code: 200, headers {
    "Accept-Ranges" = bytes;
    "Cache-Control" = "max-age=237";
    Connection = "keep-alive";
    "Content-Encoding" = gzip;
    "Content-Length" = 4402;
    "Content-Type" = "text/html; charset=UTF-8";
    Date = "Fri, 07 Feb 2014 05:52:51 GMT";
    Expires = "Fri, 07 Feb 2014 05:56:48 GMT";
    Server = Apache;
    Vary = "Accept-Encoding";
    Via = "1.0 proxy1.screen.co.jp (squid)";
    "X-Cache" = "MISS from proxy1.screen.co.jp";
    "X-Cache-Lookup" = "HIT from proxy1.screen.co.jp:8080";
} }, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}

Fand ich die Nachricht Request failed: unacceptable content-type: text/html so verstehe ich, ich habe damit text/html akzeptabel. Dann habe ich noch die Zeile: manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];.

AFHTTPRequestOperationManager *manager 
= [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes
= [NSSet setWithObject:@"text/html"]; //###### ADDED LINE ######
[manager GET:@"http://www.apple.com/jp" parameters:nil
     success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"HTML: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

Aber dies scheiterte auch.

2014-02-07 14:55:48.927 Tests[1873:70b]
Error: Error Domain=NSCocoaErrorDomain Code=3840
"The operation couldn’t be completed. (Cocoa error 3840.)"
(JSON text did not start with
array or object and option to allow fragments not set.)
UserInfo=0xfa7b870 {NSDebugDescription=
JSON text did not start with
array or object and option to allow fragments not set.}

Danke für Eure Hilfe.

InformationsquelleAutor Feel Physics | 2014-02-07
Schreibe einen Kommentar