AFNetwork 2.0 error code =-1016 and 3840 in request, afnetwork-1016

Source: Internet
Author: User

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];




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.