简体   繁体   English

如何在+呼叫后内容类型中转义+作为application / x-www-form-urlencoded

[英]How to escape + in post call content type as application/x-www-form-urlencoded

I have a ajax call with content type: xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 我有一个内容类型为ajax的调用:xhr.setRequestHeader('Content-Type','application / x-www-form-urlencoded');

Now I have a data like: "firstName=bob+builder"; 现在,我有一个数据,例如:“ firstName = bob + builder”;

When the data is sent to the server the browser replaces the + sign with space and the data goes as firstName: bob builder 当数据发送到服务器时,浏览器用空格替换+号,并且数据以firstName的形式出现:bob builder

Is there a way to escape that + sign? 有没有办法逃避那个+号? as far as I know there is no way except that it should be handled on the server side, replacing space with + sign. 据我所知,除了应该在服务器端处理之外,没有其他方法,用+号代替空间。 Am I wrong? 我错了吗?

You should be able to encode on the client side. 您应该能够在客户端进行编码。 With Javascript: 使用Javascript:

encodeURIComponent("bob+builder"); //bob%2Bbuilder

The server side code should then simply decode. 然后,服务器端代码应简单地解码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在节点js中使用参数为application / x-www-form-urlencoded类型的POST调用 - How to consume POST call where parameter is of type application/x-www-form-urlencoded in node js 如何使用应用程序 / x-www-form-urlencoded 发送 axios 帖子? - How to send axios post with application / x-www-form-urlencoded? 如何使发布请求具有bas ic auth和内容类型x-www-form-urlencoded - how to make post request baswith ic auth and content type x-www-form-urlencoded “axios.defaults.headers.common['Content-Type'] = 'application/json'” 但 axios.post 仍然是“application/x-www-form-urlencoded” - "axios.defaults.headers.common['Content-Type'] = 'application/json'" but axios.post still is "application/x-www-form-urlencoded" 使用内容类型为 application/x-www-form-urlencoded 的 POST Fetch 调用时,从服务器返回的本机 422 不可处理实体错误 - React native 422 Unprocessable Entity error returned from server when using POST Fetch call with content type: application/x-www-form-urlencoded 如何使用在Content-Type标头中同时具有“ application / x-www-form-urlencoded”和“ charset = UTF-8”的Javascript发布HTML表单 - How to post a HTML form using Javascript that has both “application/x-www-form-urlencoded” and “charset=UTF-8” in the Content-Type header 使用 x-www-form-urlencoded content-type 将嵌套的 object 作为 formdata 发布 - post nested object as formdata using x-www-form-urlencoded content-type file_get_contents():假设应用程序/x-www-form-urlencoded 未指定内容类型 - file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded HttpMediaTypeNotSupportedException:不支持内容类型 'application/x-www-form-urlencoded;charset=UTF-8' - HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported "ajax、setRequestHeader()、Content-Type、application\/x-www-form-urlencoded 和 charset" - ajax, setRequestHeader(), Content-Type, application/x-www-form-urlencoded and charset
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM