iOS server data Request "Chinese character coding" issue

Source: Internet
Author: User

The following records the data request problem:

1. Do not know that we have encountered the wood, when the URL of the data request with Chinese characters, the request data will be reported 404 error, that is, the parameters or interface URL Error < Although 404,500 and other errors are generally a server problem, but ... What I want to say is that most of us ask for parameters or URL problems yo!!! >

At this time you will have to check your request parameters and address is not wrong yo!

2. When the data request with the Chinese characters, it is generally to be converted to UTF8 encoding, in order to make data requests.

     NSString *searchstr1 = [Searchstr stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];

Some data may be transferred once enough, some .... But not necessarily.

Please look down at yo ...

3. Android seems to be a transcoding just fine ... It's just ... iOS doesn't seem to work ... Hehe!!!

Anyway, I tried a lot of times do not, has been reported 404 errors .... After many attempts, it is finally found how to solve the problem ...

The solution is: two times UTF8 transcoding

Look at the following my Code implementation: Enter Chinese to search for request data.

1 #pragmaMark-uisearchdelegate2 3- (void) searchbarsearchbuttonclicked: (Uisearchbar *) searchbar{4     5Self.searchBar.showsCancelButton =NO;6 [Searchbar Resignfirstresponder];7     //Request search Data8NSString *searchstr =[Searchbar.text stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];9NSString *SEARCHSTR1 =[Searchstr stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];TenSelf.searchtext =searchStr1; One  A     //Note that you need to transcode two times to succeed!!! - [self requeststudentlist:searchstr1]; -}

iOS server data Request "Chinese character coding" issue

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.