gpt4 book ai didi

javascript - encodeURIComponent() 似乎没有使用 dojo.xhrPost() 编码 '+' 字符

转载 作者:行者123 更新时间:2023-11-28 02:10:13 25 4
gpt4 key购买 nike

我正在尝试对作为 POST 请求中的参数传递的 URL 进行编码。 URL 包含“+”字符,而 javascript 的encodeURIComponent() 似乎没有对这些字符进行编码。知道为什么会出现这种情况吗?

代码:

var url = "http://........"
url += "&url=" + encodeURIComponent(params.url);

var deferred = dojo.xhrPost({
url: url,
headers: { "X-Requested-With": null },
sync: true,
load: function(responseObject, ioArgs) {
console.info(".....................");
params.onSuccess();
},
error: function(error) {
console.error("Error uploading image" + error);
params.onError();
}
});

实际网址:

http://......../images/I/41zMWkv3+9L._CLa|500,500|41c4imMJhOL.jpg,31PAFct+UsL.jpg_.jpg

编码后的网址:

http://......../images/I/41zMWkv3+9L._CLa%7C500,500%7C41c4imMJhOL.jpg,31PAFct+UsL.jpg_.jpg

“|”字符被编码,但“+”未被编码。

这会导致 URL 在服务器端被解码为以下 URL(“+”替换为“”):

http://......../images/I/41zMWkv3 9L._CLa|500,500|41c4imMJhOL.jpg,31PAFct UsL.jpg_.jpg

如果有任何帮助,我将不胜感激。

谢谢

最佳答案

当我使用 encodeURIComponentdecodeURIComponent() 处理此字符 + 或反 的查询字符串时,我也遇到了这个特殊问题>''

我必须使用 replace("", "+");

我说这是正常的,因为看看这个网站,它也使用了替换 SITE该网站建议解码时用 替换 +,因为 unescape 不会

我尝试使用 + 编码 %2B DEMO

或者使用 decodeURIComponent() 但你不想要 DEMO

可以使用 var url=document.location.search; 处理变量内的 url,该变量仅包含 .html 之后的部分

重复:

search          Returns the query portion of a URL

示例:

http://localhost:8100/index2?json_data=demo_title%24+Demo+title+%23+proc1_script%24+

document.location.search:

?json_data=demo_title%24+Demo+title+%23+proc1_script%24+

使用replace或其他方法后,您可以使用

更改网站的网址
document.location.href="index2"+url;

您可以使用index.htmlexercise.html更改index2(您必须知道)

您可以在此 site 上查找所有字符的编码

更新

您尝试使用以下代码:

var url = "http://........"
url += "&url=" + encodeURIComponent(params.url);
//There is a error because miss `?` then you replace `"?url="` else leave so

var deferred = dojo.xhrPost(xhrArgs);
var xhrArgs= {
url: url,
headers: { "X-Requested-With": null },
sync: true,
load: function(responseObject, ioArgs) {
console.info(".....................");
params.onSuccess();
},
error: function(error) {
console.error("Error uploading image" + error);
params.onError();
}
});

什么是params???

关于javascript - encodeURIComponent() 似乎没有使用 dojo.xhrPost() 编码 '+' 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17223874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com