url decode problem 解決方法
更新時間:2011年12月26日 21:45:03 作者:
今天被告訴了一個奇怪的事兒,第三方網(wǎng)站使用我們提供的簽名是出現(xiàn)了錯誤,原因是使用php的urldecode時把加號(+) 替換成了空格
試驗了一下python的urllib庫以及js 的 encodeURIComponent 均不會替換。空格encode也是替換成了 '%20' 。python提供了urllib.quote_plus, urlib.unquote_plus來處理空格->加號,看起來還是比較合理的。
查了一下 RFC 3986: 有下面一段
Scheme names consist of a sequence of characters beginning with a letter and followed by any combination of letters, digits, plus ("+"), period ("."), or hyphen ("-").
RFC 2396 有下面的一段
The plus "+", dollar "$", and comma "," characters have been added to those in the "reserved" set, since they are treated as reserved within the query component.
表示加號已經(jīng)是url的保留字了,不需要轉(zhuǎn)義。
然后html4文檔里才有關(guān)于加號的轉(zhuǎn)義:
application/x-www-form-urlencoded
Forms submitted with this content type must be encoded as follows:
Control names and values are escaped. Space characters are replaced by`+', and then reserved characters.....
聲明只有content-type為application/x-www-form-urlencoded時才會對+做轉(zhuǎn)義。
又翻了下php的文檔,發(fā)現(xiàn)有一個
rawurlencode() - URL-encode according to RFC 3986
也就是php又搞了rawurlencode和rawurldecode把標(biāo)準實現(xiàn)了。。。。
不能反一下么,畢竟大部分人應(yīng)該都會用urlencode。php真是蛋疼啊。。。。
查了一下 RFC 3986: 有下面一段
Scheme names consist of a sequence of characters beginning with a letter and followed by any combination of letters, digits, plus ("+"), period ("."), or hyphen ("-").
RFC 2396 有下面的一段
The plus "+", dollar "$", and comma "," characters have been added to those in the "reserved" set, since they are treated as reserved within the query component.
表示加號已經(jīng)是url的保留字了,不需要轉(zhuǎn)義。
然后html4文檔里才有關(guān)于加號的轉(zhuǎn)義:
application/x-www-form-urlencoded
Forms submitted with this content type must be encoded as follows:
Control names and values are escaped. Space characters are replaced by`+', and then reserved characters.....
聲明只有content-type為application/x-www-form-urlencoded時才會對+做轉(zhuǎn)義。
又翻了下php的文檔,發(fā)現(xiàn)有一個
rawurlencode() - URL-encode according to RFC 3986
也就是php又搞了rawurlencode和rawurldecode把標(biāo)準實現(xiàn)了。。。。
不能反一下么,畢竟大部分人應(yīng)該都會用urlencode。php真是蛋疼啊。。。。
相關(guān)文章
ThinkPHP自動轉(zhuǎn)義存儲富文本編輯器內(nèi)容導(dǎo)致讀取出錯的解決方法
這篇文章主要介紹了ThinkPHP自動轉(zhuǎn)義存儲富文本編輯器內(nèi)容導(dǎo)致讀取出錯的解決方法,需要的朋友可以參考下2014-08-08PHP幾個數(shù)學(xué)計算的內(nèi)部函數(shù)學(xué)習(xí)整理
下面主要講述 round, floor, ceil, pow, rand,max, min, decbin, bindec, dechex, hexdec, decoct, octdec 函數(shù)。2011-08-08php實現(xiàn)插入數(shù)組但不影響原有順序的方法
這篇文章主要介紹了php實現(xiàn)插入數(shù)組但不影響原有順序的方法,實例分析了php數(shù)組操作的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03PHP發(fā)送郵件確認驗證注冊功能示例【修改別人郵件類】
這篇文章主要介紹了PHP發(fā)送郵件確認驗證注冊功能,結(jié)合實例形式分析了PHP開源郵件操作類的修改與使用技巧,需要的朋友可以參考下2019-11-11