AFNetwork 2.0 error code=-1016 and 3840 in the request
-1016 appears when making a network request because only
text/json, application/json, text/javascript are supported.
You can add text/html
once and for all . Search for self.acceptableContentTypes in
AFURLResponseSerialization.h and add @"text/ html",@"text/plain" This will solve the -1016 error but it will be followed by 3840 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=0x9152780 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.} You will find this error occurs how What to do? Add the following statement to solve the problem manger.requestSerializer = [AFHTTPRequestSerializerserializer];
manger.responseSerializer = [AFHTTPResponseSerializerserializer];
is it successful? It's successful! But a new problem arises, encoding problem. If the server returns a, you receive <61>
. How can this work?
When you use a browser to request It is found that the response header Content-Type: text/html;charset=UTF-8 is like this,
but afNetwork request is Content-Type:text/plain;charset=ISO-8859-1, which is inconsistent.
Why is it accessed by the pc browser? Is it inconsistent with accessing with afNetwork? I don’t know what’s going on?
Then I found that in fact, I can add the following two sentences without modifying the contents of
AFURLResponseSerialization.h. manger.requestSerializer = [AFHTTPRequestSerializerserializer];
manger.responseSerializer = [AFHTTPResponseSerializerserializer]
; Convert the encoding to the
responseObject and it will be OK
NSData *doubi = responseObject;
NSString *shabi = [[NSString alloc]initWithData:doubi encoding:NSUTF8StringEncoding];
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326864822&siteId=291194637
Recommended
Ranking