Encode JavaScript code into gb2312 encoding function (urlencode)

Source: Internet
Author: User

 

I didn't think it was before. Today I found that Asp.net will help us encode the data when passing parameters! It is also shameless that it cannot be canceled to Prevent Automatic decoding.

For example, search. aspx? Key = China, will automatically first use UTF-8 encoding in the transfer process, and then request. querystring ["key"] Decoding by UTF-8.

However, if we pass the encoding with gb2312 before, it will be encoded with UTF-8 again and then decoded.

After searching for the Internet for half a day, some methods are to add the specified encoding method in the <system. Web> Configuration section of Web. config;

<Globalization fileencoding = "gb2312" requestencoding = "gb2312" responseencoding = "gb2312"/>
After modification, we found it worked! But soon I got depressed, because the request. querysring ["key"] was decoded using gb2312, but the encoding was still UTF-8, tangled up

Because the JS redirection I used when passing Parameters

Window. Location. href = search. aspx? Key = "China ";

However, the received value is response. Write (request. querysring ["key"]); it is a Juan, which makes me hurt.

After analyzing how China becomes a Juan, I found that it was obtained after UTF-8 encoding and then gb2312 decoding. If I first encoded it with gb2312 and then transmitted it to gb2312 for decoding, the problem should be solved, so I found that JS does not provide gb2312 encoding functions, and only a few functions are encoded with UTF-8,

Finally, I tried to find the conversion function window. Location. href = search. aspx? Key = urlencode ("China ");

 

/***** This JavaScript writen by 51js. COM-ZMM () ****/function urlencode (vstr) {var vget = new string (); vaR gbdata = ['Ah, Ah, sorry, no cancer, no problem, no problem, no ammonia, no acid, no. ba ba Bai banban move pull like board Board dress mix with flap half Office the Bangbang Bang bang ', 'thin hail bao burst cup Bei times embarrassed to prepare the baking was Ben benzene Ben stupid collapse stretch Pressure Pump burst forced nose bi binbin binbing bing ', 'disease and bo cai weishen silkworm residue miserable can Cang Zang operation rough groove Cao toilet policy side volume test layer rub cross cutting tea Cha cha ', 'The farm often has a long compensation for changchang changsong advocate ultra-copy notes to laugh at the tide of the nest, quarrel, stir-fry the car, pull away from the Chen Shen chen yu lining support called the City cheng the silk looks ugly and the smell begins to exit the cupboard ', 'chu Chu Yu touchpoint chuchuan Chuan string sore window building bed Chuang blow Yan hammer down Chun alcohol lips pure stupid stamp Z magnetic female ci CI Ci this thorn is sent to the congcong scallions from the congcong to gather together the crude vinegar cluster to promote the destruction of the Cui reminder brittle essence of the quenching village Cun inch learn to learn from the scrubbed measures against the wrong set up to answer a big stay he needs to wear a loan replacement bag ', 'slack Dan island prayer Dao De de stool Deng Di di Dian let's take a drop in the hook and take a drop in the pie chart ', ding ding end of short forging segment broken satin heap against the team of dunton squatted dunton blunt shield trembling Duo rudder yi Evil er can suppress ELE. Me and ER bait two ', 'The issue of penalty raft cutting missing valve law Fan bandits bark lung waste boiling Fen FENG Yu Feng Fu skin incubate Fu ', 'fu Fu gan Gang gang Gao Bing cake do pick draft report Ge gego splits the chromium into different roots to help more ', 'gong Gong mercury gonggong Gong Gou Gu gu hired guoguo, guoguo, guoguan, guanguan, guanguan, canal, canal, Guoguang, guanguang, and guogui. guoguo Guo ', 'The Child in the sea he Hai attack Han hahao Hao good consumption Hao hehao Heo nuclear hehe hehe hehehe hehe heh He he Heng He he H Hu HU Yu Hu HU hu ', 'arc Hu HU huadao slide painting cut words Huai bad Huan HUan phantom Huang Zho reed Huang Yao Lie gray hui Yin wedding soul muddy mixed living group fire get or confuse Huo's attack on the computer ', 'ji Ji jijia Jia ke Jia Jian jian Ji ', 'jian Jian Jiang propeller award Jiang Jiao Zheng Jiao Jian handed in the cutting-and-cutting tutorial, jiaojie jie Jin jin Lijin only Lijin Jin ban near-bo dip ', jing save the old JU Xi JU jue Jun ', 'Jun Kai-Jun-gun Jun ka-ka Kai-kai-ke-ke class will chew Ken kukeng Kong empty fear Kong control Kou dry cry cave bitter cool library pants boast cross-block chopsticks Yi fast wide Kuang basket crazy frame mine eye Kuang Condition looking at Kwai kuikui ', 'The kubernetes bundle, sleepy, expanded, wide, pull, wax, wax, la Lai, Lai, lan LAN lang Lao suo Lao Li Lei Li li LI Shi Li ', 'liuli Lili Li Lian Liang Xiao Xi Yu Lian Li liao reported the leeching of Liao material, the leeching of the leeching forest, and the Linlin of the neighboring scales, the Ling. liu xiaoliu Liu liulong, Liu xiaoliu ', 'Long ridge gather Lou Liu Lu chlorine law rate filters Lugu luanyi eggs out of chaos slightly round Lun Ma bury Mai Yu man ', 'too busy Mao mei enzyme mold coal No Mei media magnesium per Mei men Meng mi Min chilo Mingming ', 'Mo mo Mu na Ma Mu nai Nan capsule scratching the brain annoying it neighborhood niigniang urine you have been cutting your teeth ', 'screwed up the ox and twisted the nets, and the nounu, the Nuu, The Nuo, the Nuu pan peng holds the touch on the blank, and the batch is split on the other side ', 'beer, pig, PI, p, p pu Qi qi Qiqi, Qi qique ', 'qachin qianqian Qian Before the clamp, you may send a shallow cut, an unapologetic gun, and a great wall, and a strong force to grab a slide. The shovel knocks on the bridge, and the Qiao CIDR, And the Qiqiao Qiao CIDR, cut the eggplant, and steal the Qin invasion. qin qing Qiong Qiu Zheng qu ', 'Take taobaoququ to circle Quan jie Yi but que really que skirt group Ran dirty soil bustling so that Rao disturbance around provoke hot liren Ren recognize the blade when throwing is still sun Rong ruirui ruirun ruiru soft Fuxi the weak sash and sash ', 'umbrella sansong funeral Sao sweep sissy sensan Sensa Sha Shan smudge injury business rewards Shang Xiao Shen shen Sheng suo ', 'The province has exceeded the Shengshi loss of the lion Shi Xi Shi shi shu Shu shu ', 'Don't brush, drop, tie, shushuang Shuang, who sleep, tax, suck, Shun, say Shuo Si si although su acid garlic is counted as Sui, Sui, tunnel, Sun loss, bamboo shoots, soup, shrink, and lock, he and her tower ', 'otta tartan Tan tang tang tao Zhan set special Teng pain ti Tian Yi yi pick a piece of yellow jump post tie hall to listen to hydrocarbon ', 'ting Ting boat Tong bucket stab tube system pain stealing throwing head through convex bald toutu Tutu turbulent Tusi leg Rolling fade back swallow Tun buttocks drag Tuo dig wow frog Wa wa so Wan wang ', 'wei Wei Wen Jian Wen Zheng q: I have been lying in the wowu Wu wuwu Wu wu Xixi Xi se Si Xi ', 'Xi Xi Xia Xian Xiang xiang Xiao ', 'xiao Xiao Xie xing Xiong Xiu Shu Xi XU Xu Xian xu XuXu xuxuan Xuan ', 'election of Xuan boots Xue Xun Jie ya yan Qi Yang yang Yao ', yao Ye yi suspected yi Yin yin ', 'ying Ying Yong Yu youyou Yu yu ', 'bath yuyu Yu Yuanyuan Yuan yun Xi zai again in my temporarily likes dirty burial by bad chisel algae jujube early bath flea noise make soap stove dry responsibility selection Zeze how can I add a hacker ', 'You can't crack the gate, but you can't crack it. You can't pick the Zhai's narrow debts. Zhan felt Zhan sticks to the Zhan Zhang zhangzhang rose. zhangzhang Account accounts battle expansion and damage zhazhao looking for Marsh Zhao cover Zhe zhe ge cane this Zhe Zhen needle detection pillow rash Diagnosis zhenzhen zhengzheng ', 'frame disease Zheng Zhizhi zhijiao Zhizhi Zhi rank zhizhizhizhizhizhizhizhizhongzhongzhongzhongzhongzhongzhongzhongzhongzhongzhongzhongzhongzhongzhouzhouzhouzhouzhouzhoupiao Piao axis elbow curse wrinkle Zhou day burst Zhu zhuzhu the candle is too far-sighted, and the main pillar helps to store and build ', 'Live note I wish to grasp the claw tug professional bricks to create and earn the pile Zhuang makeup hit the zhuanglike vertebral cone chasing actor pendant with a pair of quasi catch Zhuo table Zhuo watching the Zhuo zadvisory zizizizi Zizi Zi Zheng Zou seat ', 'awkwardly connected zookeeper zookeeper zookeeper please wait until there are too many threads in the queue. Please wait until then ', 'zookeeper zookeeper there are two major challenges: there are two major problems ', 'zookeeper has been a tough nut to crack. i'm a joke, and I'm a joke. when there are too many other users, there are too many other users ', ''when the system is busy I have been reading and writing, and I have been reading, reading, writing, and reading ', 'zookeeper zookeeper flushula inqin yinqi libenyi niyuncin niignition please refer to the following link for more information ', 'zookeeper zookeeper please refer to the following: when there are too many other users, there are too many other users ', 'zookeeper hybridhybriddb hybriddb for MySQL has been released. these two problems have been solved. when the hacker clicks, the hacker clicks, and then the hacker clicks ', '?__________________________________________________________________________________________________________________________ hey, what's the problem? I have been muttering, scaling, and scaling ', 'zookeeper zookeeper ************************************************************ please refer to the following link for more information: when there are too many other users, there are too many other users ', 'strategy' yundun zookeeper zookeeper and zookeeper was the top of the Board, as it seems, after the migration of zookeeper and other zookeeper. zookeeper and zookeeper ', 'zookeeper and zookeeper have been involved in the development of zookeeper. please refer to the following documents for more information: i'm sorry ', '{}}}{{ 'when there is a problem, there is no such problem. Zookeeper, Caojing ', 'zookeeper and zookeeper zookeeper and zookeeper please try again later ', 'zookeeper, Zookeeper, Zookeeper and zookeeper in addition you can try it all ', 'Sister-in-law, Niu, Yu, zookeeper and zookeeper when there are too many other users, there are too many other users ', 'The number of failures is very high. I have been very careful about the problem. heng Yu Xi Jinping, Kiki, James, Tom ', 'chen Yu Huang Yu zookeeper and zookeeper have been published in the United States. ', 'zookeeper zookeeper malong Moli barrium zookeeper on the neighbase tree zookeeper acer seum var. he was a hacker, he was a hacker ', 'zookeeper zookeeper huang Hui, Huang, Yu please refer to the following link for more information ', 'zookeeper zookeeper mongoshake oxy y argon and zookeeper when the system was deployed, the zookeeper and zookeeper were successfully added to the zookeeper, the zookeeper, and zookeeper. zookeeper Too many then ', 'zookeeper zookeeper Internet hub zookeeper stew zookeeper the entropy of others, the scalpers, the scalpers, And the scalpers. the swordsmanship likes and likes ', 'zookeeper zookeeper and zookeeper zookeeper is a Chinese there are two types of images ', 'zookeeper Ruiqi has a very large number of visitors. A large number of zookeeper workers have been found in zookeeper. ru, R, R, O, M, O, O, M, T zookeeper zookeeper ', 'zookeeper zoctyl ammonium retainium () Re, um, um, lithium, zirconium, osscranium, Zookeeper, and other zookeeper. zookeeper zookeeper cadmium was engraved into zookeeper. parts of the system were broken together ', 'timeout Zookeeper zookeeper zookeeper zookeeper ', 'zookeeper, Zookeeper, Zookeeper, drug addiction, Zookeeper, epilepsy, Zookeeper, and zookeeper very cute, very cute, and very cute. when there are too many other users, there are too many other users ', 'temporal zookeeper zookeeper zookeeper manipulloudcli ',' please refer to the following link for more information: ', 'zookeeper Zookeeper niignition Niigata zookeeper and zookeeper ', 'oxyloxylyl ester was found to have been found in the glutinous rice grains, and then in the glutinous rice grains. when you fail to roll over, you cannot roll over, and then you can roll over your ankle. zookeeper ', 'zookeeper and zookeeper zookeeper and zookeeper have been caught in the zookeeper system ', 'fin catfish bread catfish zookeeper catfish please refer to the following link for more information: please wait until then. for (VAR I = 0; I <vstr. length; I ++) {var TMP = vstr. charat (I); var Reg =/^ [\ u4e00-\ u9fa5 \ uf900-\ ufa2d] $/; If (Reg. test (TMP) {for (VAR area = 0; area <gbdata. length; area ++) {var place = gbdata [area]. indexof (TMP) + 1; if (place) {area + = 16; vget + = '%' + getucase (0xa0 + area ). tostring (16); vget + = '%' + getucase (0xa0 + place ). tostring (16); break ;}} else {var VPOs = '~! @ # $ % ^ & * ()-_ + = {} [] |\:; "\' <> ,.? /''. Indexof (TMP); vget + = VPOs! =-1? '%' + Getucase (TMP. charcodeat (0 ). tostring (16): TMP;} return vget. replace (/\ s/g, '+'); function getucase (v) {return v. touppercase ();}}

Found another simpler methodFirst, define the transcoding method:

        var tx = {};        tx.urlEncode = function(str) {            window.execScript("Function vbsFun(str):vbsFun=hex(asc(str)):End Function", "vbscript");            var gObject = {};            return str.replace(/[\x00-\xff]/g, function(a) {                return a.replace(/[^0-9a-zA-Z]/g, function(b) {                    if (!gObject[b])                        gObject[b] = "%" + vbsFun(b);                    return gObject[b];                })            }).replace(/[^\x00-\xff]/g, function(c) {                return c.replace(/./g, function(d) {                    if (!gObject[d])                        gObject[d] = vbsFun(d).replace(/(..)(..)/, "%$1%$2");                    return gObject[d];                })            }).replace(/%20/g, "+")        };

Directly call

var newcode=tx.urlEncode(key.value);

 

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.