On the problem of Chinese coding in Turing Robot access URL (c + + urlencode encoding process)

Source: Internet
Author: User
Tags urlencode

Recently in the development of the smart home, the sub-module called the Turing Man (http://tuling123.com/openapi/cloud/home.jsp)

But the discovery has been unsuccessful, the return value has been 4.0006 million-like debugging no results The last discovery is the problem of Chinese transcoding the general Web site will speak Chinese to do a transcoding, for the time being called UrlEncode

Transcoding process is very simple, because the Chinese encoding is not a byte, but a number of bytes (ASCLL code is two, Unicode code is three), the transcoding process is actually the Chinese characters by byte output as:

%+ the byte hexadecimal expression

For example, the ' ah ' word bit output is



Then transcoding after the ' ah ' word for%B0%A1 (ASCLL code), the same reason Utf-8 code ' ah ' after the word transcoding for%e5%95%8a

and letters, numbers, and some symbols are underlined, ~ etc. are not encoded.

Also note: Spaces are not allowed to be encoded as + in URLs

The UrlEncode encoded code can be written accordingly.


/* ****************************************** Title:urlencode transcode (ASCLL version) ***************************************** * date:2014/12/05****************************************** Author: Liu Xu ****************************************** * /#include "stdafx.h" #include <string> #include <iostream>using namespace std;typedef unsigned char BYTE; byte int_to_hex (const byte src) {return src > 9? (src+55): (src+48);} string encode (const string src) {string result = ""; int length = Src.length (); int pos = 0;//The length of the result string is marked for (int i = 0; i < length; i++) {if (Isalnum ((BYTE) src[i]) | |/* Determines whether the letter or number must be type-cast */': ' = = src[i]| | '   _ ' = = src[i]| |   '. ' = = src[i]| | ' ~ ' = = src[i]| | '? ' = = src[i]| | ' & ' = = src[i]| | ' = ' = ' = ' = Src[i]) {//Because the project needs, here I keep a few characters commonly used in the URL, other characters please query, time problem, not much to do supplement result + = src[i];//remain unchanged}else if (' = = Src[i]) {//If it is a space resu Lt + = "+";}  else {//If the other character is BYTE temp = Int_to_hex ((byte) src[i]); result + = "%"; result + = Int_to_hex ((byte) src[i] >> 4); Result + = Int_to_hex ((BYTE) src[i]% 16); }}return result;} int main () {string src= "Hello"; string dest = Encode (src); Cout<<dest<<endl;return 0;}



On the problem of Chinese coding in Turing Robot access URL (c + + urlencode encoding process)

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.