为什么要对POST XHR请求体中的数据进行encodeURIComponent()? [英] why encodeURIComponent() for data in body of POST XHR request?

查看:151
本文介绍了为什么要对POST XHR请求体中的数据进行encodeURIComponent()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我读过的所有Ajax库都使用encodeURIComponent()对名称 -

值对在POST之前从表单中提取使用和xmlhttprequest导致

服务器。我可以理解为什么在GET请求的情况下需要这个编码是
,并且表单数据作为URI查询字符串附加为

;但是,为什么POST

请求所需的编码?


谢谢,

彼得

Hi,

All Ajax libraries I''ve read use encodeURIComponent() on the name-
value pairs extracted from forms before POST ing the result to the
server with and xmlhttprequest. I can understand why this encoding is
required in the case of a GET request and the form data is attached as
a URI query string; however, why is the encoding necessary for POST
requests?

Thanks,
Peter

推荐答案

8月2日上午12:43,Peter Michaux< petermich ... @ gmail.comwrote:
On Aug 2, 12:43 am, Peter Michaux <petermich...@gmail.comwrote:




我读过的所有Ajax库都使用了在POST之前从表单中提取的名称 -

值对上的encodeURIComponent()使用和xmlhttprequest将结果发送到

服务器。我可以理解为什么在GET请求的情况下需要这个编码是
,并且表单数据作为URI查询字符串附加为

;但是,为什么POST

请求所需的编码?


谢谢,

Peter
Hi,

All Ajax libraries I''ve read use encodeURIComponent() on the name-
value pairs extracted from forms before POST ing the result to the
server with and xmlhttprequest. I can understand why this encoding is
required in the case of a GET request and the form data is attached as
a URI query string; however, why is the encoding necessary for POST
requests?

Thanks,
Peter



URL编码只是HTTP

请求中名称 - 值对的标准。 GET或POST没有进入它(这些对在POST请求中看起来与

相同,就像它们在查询时所做的那样

字符串用于GET。 )


例如,想象一下如果你没有编码对子会发生什么情况

并且其中一个值中有一个&符号。 />

URL encoding is simply the standard for name-value pairs in an HTTP
request. GET or POST doesn''t enter into it (the pairs look exactly
the same in a POST request as they do when tacked onto the query
string for a GET.)

For example, imagine what would happen if you didn''t encode the pairs
and one of the values had an ampersand in it.


David Mark于2007年8月2日在comp.lang.javascript中写道
David Mark wrote on 02 aug 2007 in comp.lang.javascript:

8月2日上午12:43,Peter Michaux< petermich ... @ gmail.comwrote:
On Aug 2, 12:43 am, Peter Michaux <petermich...@gmail.comwrote:

>>
我读过的所有Ajax库都使用encodeURIComponent()对表单中提取的名称 -
值对,然后将结果发送到
服务器和xmlhttprequest。我可以理解为什么在GET请求的情况下需要这种编码,并且表单数据作为URI查询字符串附加;但是,为什么POST
请求需要编码?
>>
All Ajax libraries I''ve read use encodeURIComponent() on the name-
value pairs extracted from forms before POST ing the result to the
server with and xmlhttprequest. I can understand why this encoding is
required in the case of a GET request and the form data is attached as
a URI query string; however, why is the encoding necessary for POST
requests?



URL编码只是HTTP

请求中名称 - 值对的标准。 GET或POST没有进入它(这些对在POST请求中看起来与

相同,就像它们在查询时所做的那样

字符串用于GET。 )

例如,想象一下如果你没有编码对子会发生什么情况

并且其中一个值中有一个&符号。


URL encoding is simply the standard for name-value pairs in an HTTP
request. GET or POST doesn''t enter into it (the pairs look exactly
the same in a POST request as they do when tacked onto the query
string for a GET.)
For example, imagine what would happen if you didn''t encode the pairs
and one of the values had an ampersand in it.



使用POST时,没什么可以的,我想。

-

Evertjan。

荷兰。

(请在我的电子邮件地址中将x'变为点数)

When using POST, nothing would, I would imagine.
--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


8月2日,3日:上午18点,Evertjan。 < exjxw.hannivo ... @interxnl.netwrote:
On Aug 2, 3:18 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:

David Mark于2007年8月2日在comp.lang.javascript中写道

8月2日上午12:43,Peter Michaux< petermich ... @ gmail.comwrote:
On Aug 2, 12:43 am, Peter Michaux <petermich...@gmail.comwrote:


我读过的所有Ajax库都使用encodeURIComponent()对名称 -

值对在POST结果之前从表单中提取使用和xmlhttprequest到

服务器。我可以理解为什么在GET请求的情况下需要这个编码是
,并且表单数据作为URI查询字符串附加为

;但是,为什么POST

请求所需的编码?
All Ajax libraries I''ve read use encodeURIComponent() on the name-
value pairs extracted from forms before POST ing the result to the
server with and xmlhttprequest. I can understand why this encoding is
required in the case of a GET request and the form data is attached as
a URI query string; however, why is the encoding necessary for POST
requests?


URL编码只是HTTP

请求中名称 - 值对的标准。 GET或POST没有进入它(这些对在POST请求中看起来与

相同,就像它们在查询时所做的那样

字符串用于GET。 )

例如,想象一下如果你没有编码对子会发生什么情况

并且其中一个值中有一个&符号。
URL encoding is simply the standard for name-value pairs in an HTTP
request. GET or POST doesn''t enter into it (the pairs look exactly
the same in a POST request as they do when tacked onto the query
string for a GET.)
For example, imagine what would happen if you didn''t encode the pairs
and one of the values had an ampersand in it.



使用POST时,没什么可以的,我想。


When using POST, nothing would, I would imagine.



这是什么意思?你当然可以使用&符号来表示数据表格

,它们的编码方式与GET请求的编码方式相同。

What does that mean? You can certainly POST form data with ampersands
and they are normally encoded the same way as GET requests.


这篇关于为什么要对POST XHR请求体中的数据进行encodeURIComponent()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆