AFNetwork 2.0 error code =-1016 and 3840 in request, afnetwork-1016
When a network request is made,-1016 is displayed because only network requests are supported.
Text/json, application/json, text/javascript
You can add text/html
Once and for all
AFURLResponseSerialization. h
Search in
Self. acceptableContentTypes
Then add
@ "Text/html", @ "text/plain"
In this way, the error of-1016 can be solved.
However, the 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
What should I do?
Add the following statement to solve the problem.
Manger. requestSerializer = [AFHTTPRequestSerializerserializer];
Manger. responseSerializer = [AFHTTPResponseSerializerserializer];
Is it successful! However, the encoding problem occurs. If the server returns a, what you receive is <61>
How can this happen?
The Response Header Content-Type: text/html; charset = UTF-8 is like this when you use a browser to request
However, the afNetwork request is Content-Type:Text/plain; charset = ISO-8859-1 is so inconsistent
Why is access from a pc browser inconsistent with that from a afNetwork? What is unknown?
Then you can add the following two sentences without modifying them.AFURLResponseSerialization. h
Manger.RequestSerializer= [AFHTTPRequestSerializerSerializer];
Manger.ResponseSerializer= [AFHTTPResponseSerializerSerializer];
Set the received
ResponseObject converts the encoding to OK.
NSData* Doubi = responseObject;
NSString* Shabi = [[NSString Alloc]InitWithData: DoubiEncoding:NSUTF8StringEncoding];