问题标签 [encodeuricomponent]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
4960 浏览

asp.net - 在 .Net http 处理程序中编码 au umlaut 时遇到问题

我有一个 JavaScript 请求到一个 ASP.Net (2.0) HTTP 处理程序,该处理程序将请求传递给一个 java web 服务。在此系统中,特殊字符(例如带有重音符号的字符)无法正确传递。

例如

  • 人工输入:Düsseldorf
  • 成为一个 JavaScript 异步请求http://site/serviceproxy.ashx?q=D%FCsseldorf,据我所知,它在 ISO-8859-1 和 UTF-8 中都有效。(除非它是 UTF-8 中的 %c3%bc )
  • HttpContext.Current.Request.QueryString.Get("q")返回D�sseldorf这是麻烦开始的地方。
  • HttpUtility.UrlEncode(HttpContext.Current.Request.QueryString.Get("q"), Encoding.GetEncoding("ISO-8859-1"))返回D%3fsseldorf(一个'?')
  • HttpUtility.UrlEncode(HttpContext.Current.Request.QueryString.Get("q"), Encoding.UTF8)返回D%ef%bfsseldorf

所以它的值没有被正确解码或重新编码以传递给java服务。

  • 通知HttpContext.Current.Request.Url.Query?q=D%FCsseldorf&output=json&from=1&to=10
  • 虽然HttpContext.Current.Request.QueryString.ToString()q=D%ufffdsseldorf&output=json&from=1&to=10

为什么会这样,我怎样才能告诉它HttpContext尊重请求标头,其中包括:

QueryString并使用 UTF-8 字符集解码 URL 。

附录:正如答案所指出的,问题不在于解码,而在于编码;using escape()in JavaScript 不会根据 UTF-8 转义,而 usingencodeURIComponent()会。

0 投票
5 回答
69205 浏览

php - PHP 中 JavaScript 的 encodeURIcomponent 等价物是什么?

encodeURIcomponentPHP中JavaScript的函数等价物是什么?

0 投票
4 回答
1799 浏览

php - ∞ 在插入 MySQL 表时转换为 ∧

0 投票
2 回答
2487 浏览

php - encodeURIComponent is really useful?

Something I still don't understand when performing an http-get request to the server is what the advantage is in using JS function encodeURIcomponent to encode each component of the http-get.

Doing some tests I saw the server (using PHP) gets the values of the http-get request properly also if I don't use encodeURIcomponent! Obviously I still need to encode at client level the special character & ? = / : otherwise an http-get value like this "peace&love=virtue" would be considered as new key value pair of the http-get request instead of a one single value. But why does encodeURIcompenent encodes also many other characters like 'è' for example which is translated into %C3%A8 that must be decoded on a PHP server using the utf8_decode function.

By using encodeURIcomponent all values of the http-get request are utf8 encoded, therefore when getting them in PHP I have to call each time the utf8_decode function on each $_GET value which is quite annoying.

Why can't we just encode only the & ? = / : characters?

see also: JS encodeURIComponent result different from the one created by FORM It shows that encodeURIComponent does not even encode properly because a simple browser FORM GET encodes characters like '€', in different way. So I still wonder what does this encodeURIComponent is for?

0 投票
2 回答
6215 浏览

javascript - JS encodeURIComponent 结果与 FORM 创建的结果不同

我认为在表单中输入的值已由浏览器正确编码。

但是这个简单的测试文件“test_get_vs_encodeuri.html”表明它不是真的:

点击提交按钮时:

encodeURICompenent 将输入值编码为“Euro-%E2%82%AC”

而浏览器进入 GET 查询只写了一个简单的“Euro-%80”

  1. 有人可以解释一下吗?

  2. 我如何使用 Javascript 以与 borwser 的 FORM (windows-1252) 相同的方式对所有内容进行编码???(转义功能不起作用,encodeURIComponent 也不起作用)?

还是 encodeURIComponent 进行了不必要的转换?

0 投票
1 回答
1474 浏览

jquery - Handling of Japanese with Jquery.serialize();

Hoo boy. A weird one I guess!

getting input from a form, I want to make sure there are no western characters, punctuation or numbers before sending it to a php script for creating some xml...

from form name = "a"

---> text goes to php script using .ajax

However, the Japanese is being converted to ASCII before it gets to the regex!

eg. あああ becomes %E3%81%82%E3%81%82%E3%81%82

Any suggestions?

0 投票
2 回答
14117 浏览

javascript - 用于href的jQuery encodeURI不起作用

我在对字符串进行编码时遇到问题,因此我可以将变量放入链接中。我敢肯定这真的很简单,但是我在打开任何东西时遇到了麻烦。

这行不通。

仍然返回:

代替:

也试过:

0 投票
2 回答
1345 浏览

javascript - 如何在 JavaScript 中正确编码 URL?

我正在开发一个浏览器插件,它将当前页面的 URL 或任何选定的链接作为参数并将其发送到我们的服务器。当 url 中出现基本拉丁字母的字符时(如http://en.wikipedia.org/wiki/Vehicle),该插件可以正常工作。但是,当 URL 包含来自其他字母的字符(例如http://ru.wikipedia.org/wiki/Коляска )时,插件不起作用,我确实使用了该encodeURIComponent方法,但这似乎并不能解决问题。任何的想法?

谢谢,

奥利维尔。

0 投票
2 回答
660 浏览

php - encodeURIComponent 和 urldecode 删除斜线,为什么?

您好,我正在将 JSON.stringify 用于数组数组,它​​返回以下内容:

这是正确的,但我必须使用 encodeURIComponent (& present) 来用 js 发布这个值。问题是,当我使用 $boxes=json_decode($_POST['data']) 从 php 在 POST 中获取此数据时,它似乎删除了斜杠,例如。pt=\"7.5\" -> pt="7.5" 破坏 json 对象给出以下结果:

有没有人如何避免这个问题?谢谢

0 投票
5 回答
9455 浏览

javascript - Firefox 自动解码 url 中的编码参数,在 IE 中不会发生

我在 Firefox 和 IE 之间感到沮丧,主要是 Firefox,因为它会自动解码散列中的参数,然后我才能在 Javascript 中使用它。IE 不会自动解码 url,因此不会给我阅读错误。

我的问题类似于这个问题,除了我没有使用 ASP.NET ASP.NET MVC 自动解码来自 AJAX 的 JSON 编码参数

因此,如果我采用类似的网址example.com/#question=!%40%23%24%25^%26*(

而“!%40%23%24%25^%26*(”是使用encodeURIComponent编码的,在IE中,当我访问哈希时,它将保留为“!%40%23%24%25^%26*( ",但是在 Firefox 中,当我访问哈希时,它会自动解码为 "!@#$%^&*("

这样做的问题是,在我的脚本中,我使用 decodeURIComponent 来解码编码值,如果字符串确实被编码,这很好。由于它已经在 Firefox 中解码,它给我一个格式错误的 URI 序列错误,而 IE 根本没有给我任何错误。

我怎样才能解决这个问题?