Workarounds for unacceptable content type errors when using the afnetworking framework

Source: Internet
Author: User
Tags response code

This problem occurs when using Afnetworking 3.0:

Error domain=com.alamofire.error.serialization.response code=-1016 "Request failed:unacceptable content-type:text/ Plain

Here is the code show

1 Error domain=com.alamofire.error.serialization.response code=-1016 "Request Failed:unacceptable content-type:text/plain"

Or

1 Error domain=com.alamofire.error.serialization.response code=-1016 "Request Failed:unacceptable content-type:text/html"

This error occurs because the content type returned to the client by the server is Text/plain or text/html format, and afnetworking cannot accept these content types.

If you cannot accept any type, set or add this type. Here take Text/plain as an example.

Workaround 1: Set the AFN default resolution type

1 afhttpsessionmanager *mgr = [Afhttpsessionmanager manager];

1 mgr.responseSerializer.acceptableContentTypes = [Nsset setwithobjects:@ "text/plain ", nil];

The disadvantage of this approach is that after you set Text/plain to accept types, you cannot complete other types of parsing such as Text/json.

Workaround 2: Add the Text/plain and text/html formats to the AFN source file afurlresponseserialization.m.

Modify the No. 228 line of the file

1 self.acceptablecontenttypes = [Nsset setwithobjects:@ "application/json"@ "Text/json"@ "text/javascript", nil];

For

1 self.acceptablecontenttypes = [Nsset setwithobjects:@ "application/json"@ "text/json"@"text/javascript",@ "text/plain  ", nil];

or for

1 self.acceptablecontenttypes = [Nsset setwithobjects:@ "application/json"@ "text/json"@"text/javascript",@ "text/html  ", nil];

Add an unacceptable content type to resolve.

Workarounds for unacceptable content type errors when using the afnetworking framework

Related Article

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.