Afnetworking error message parsing

Source: Internet
Author: User
Tags response code serialization

Recently in the file upload function encountered some problems, about afnetworking failure of some error code, here to tidy up, so as not to step on the pit later:

"1" error code-999, the error message is as follows:

Error domain=nsurlerrordomain code=-999 "cancelled" userinfo={nserrorfailingurlstringkey=https://test.com/xxxxxx, Nslocalizeddescription=cancelled, nserrorfailingurlkey=https://test.com/xxxxxx}

The reason and code are as follows:

Afhttpsessionmanager *manage = [[Afhttpsessionmanager alloc] init];;        Afsecuritypolicy *policy = [Afsecuritypolicy policywithpinningmode:afsslpinningmodenone];// Error when using the certificate check mode is afsslpinningmodecertificate, but at this time the URL of the Access certificate verification is not successful, so change to Afsslpinningmodenone can        Policy.validatesdomainname = YES;        Manage.securitypolicy = policy;

"2" error code-1011,404, the error message is as follows:

Error domain=com.alamofire.error.serialization.response code=-1011 "Request failed:not found (404)" userinfo={ Nslocalizeddescription=request failed:not found (404), Nserrorfailingurlkey=https://test.com/xxxxxx, Com.alamofire.serialization.response.error.data=<>, com.alamofire.serialization.response.error.response= <NSHTTPURLResponse:0x60400c03ee80> {url:https://test.com/xxxxxx} {Status code:404, Headers {content-type: [AP Plication/octet-stream],content-length: [0],server: [Nginx],date: [Wed, May 2018 10:22:10 GMT]}}}

See this error code please do not suspect that this is the URL you want to access not access to the resulting, please check your URL

"3" error code 3840,400, the error message is as follows

Error domain=nscocoaerrordomain code=3840 "JSON text does not start with array or object and option to allow fragments not Set. " Userinfo={nsdebugdescription=json text did not start with an array or object and option to allow fragments not set., Nsunderl yingerror=0x6000058569e0 {Error domain=com.alamofire.error.serialization.response code=-1011 "Request Failed:bad Request (Userinfo={nslocalizeddescription=request Failed:bad request), nserrorfailingurlkey=https:// Test.com/xxxxxx, com.alamofire.serialization.response.error.data=<3c68746d 6c3e0a3c 68656164 3e0a3c6d 65746120 68747470 2d657175 69763d22 436f6e74 656e742d 54797065 2220636f 6e74656e 743d2274 6578742f 68746d6c 3b206368 61727365 743d4 953 20343030 3c2f6832 3e0a3c70 3e50726f 626c656d 20616363 65737369 6e67202f 772f6578 7465726e 616c2f75 706c6f61 6466696c 6 52e2052 6561736f 6e3a0a3c 7072653e 20202020 52657175 69726564 204d756c 74697061 72744669 6c652070 6172616d 65746572 202766 6c652720 6973206e 6f742070 72657365 6e743c2f 7072653e 3c2f703e 3c687220 2f3e3c69 3e3c736d 616c6c3e 506f7765 72656420 6279204a 65747479 3a2f2f3c 2f736d61 6c6c3e3c 2f693e3c 62722f3e 20202020 20202020 20202020 20202020 20202020 20202020 20202020 20202020 20202020 20202020 20202020 20202 020 0a3c6272 2f3e2020;, Com.alamofire.serialization.response.error.response=<nshttpurlresponse: 0x60400c62b5a0> {url:https://test.com/xxxxxx} {Status code:400, Headers {Date: [Tue, May 2018 01:22:33 Gmt],c Ontent-type: [Text/html;charset=iso-8859-1],content-length: [1476],cache-control: [Must-revalidate,no-cache, No-store],server: [Nginx]}}}}

This is the problem you fill the data, please check your data settings are correct, just when the problem is described as a server-side return format is not a convention JSON so can not be resolved, but ask the service colleague to check the return data is really json, Then suspect that the following return data resolvable format is not set @ "Text/json", and the check found also set the

Afhttpsessionmanager *manage = [[Afhttpsessionmanager alloc] init];        Manage.responseserializer = [[Afjsonresponseserializer alloc] init];        Manage.responseSerializer.acceptableContentTypes = [Nsset setwithobjects:@ "Application/json", @ "Text/json", @ "text/ JavaScript ", @" text/html ", @" application/x-www-form-urlencoded ", @" Multipart/form-data ", @" Text/plain ", @" image/ JPEG ", @" Image/png ", @" Application/octet-stream ", nil];

Later after further data discovery, because it is file upload, so directly using the nsdata stitching caused by the problem, error code examples are as follows:

NSData *data = [NSData datawithcontentsoffile:filepath options:nsdatareadingmapped Error:nil];    [[Afhttpsessionmanager shareinstance] Post:url_kano_uploadfile parameters:params constructingbodywithblock:^ (ID <AFMultipartFormData>  _nonnull formData) {        [formData appendpartwithformdata:data name:@ ' file '];// No such stitching is allowed here    } progress:nil success:^ (Nsurlsessiondatatask * _nonnull task, id  _nullable responseobject)    {    } failure:^ (Nsurlsessiondatatask * _nullable task, Nserror * _nonnull error) {           }];

Instead, the corresponding mimetype type should be used to differentiate the stitching

[[Afhttpsessionmanager shareinstance] Post:url_kano_uploadfile parameters:params constructingbodywithblock:^ (ID <AFMultipartFormData>  _nonnull formData) {        nserror *error;        Nsurl *fileurl = [Nsurl Fileurlwithpath:filepath];        [FormData appendpartwithfileurl:fileurl                                   name:@ "file"                               filename:filename                               mimetype:@ "Image/jpeg                                  " error:&error];    } Progress:nil success:^ (Nsurlsessiondatatask * _nonnull task, id  _nullable responseobject) {    } failure:^ ( Nsurlsessiondatatask * _nullable task, Nserror * _nonnull error) {    }];

The specific type of mimetype is not mentioned here, please consult your own study.

Afnetworking error message parsing

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.