Application/x-www-form-urlencoded of iOS development; charset=utf-8

Source: Internet
Author: User
Tags erro

Originally used to be application/json this format, do iOS commonly used network request framework afnetworking, the default is also Application/json, not long ago encountered this acceptance format problem, according to various statements on the Internet, Changed the afnetworking settings, eventually still can not solve the problem, and finally abandoned the use of afnetworking. Writing a native Web request solves the problem.

The code is as follows:

1Nshttpurlresponse *response =Nil;2 3Nserror *erro =Nil;4 5Nsmutableurlrequest *request =[[Nsmutableurlrequest Alloc]initwithurl:[nsurl Urlwithstring:urlstr]];6 7Request. HttpMethod =@"POST";8Set format9[Request AddValue:@"application/x-www-form-urlencoded; Charset=utf-8"Forhttpheaderfield:@"Content-type"];Ten// One[Request AddValue:@"2"Forhttpheaderfield:@"X-wh-token"]; AEncrypt with HMAC -NSString *serkey = [NSString hmacsha1:@""Key:key]; -  the[Request Addvalue:serkey Forhttpheaderfield:@"x-wh-signature"]; -  - [Request Sethttpbody:[body datausingencoding:nsutf8stringencoding]; -  +NSData *requesdata = [nsurlconnection sendsynchronousrequest:request returningresponse:&response Error:&erro ];

Application/x-www-form-urlencoded of iOS development; charset=utf-8

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.