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)