JavaScript-编码字符和URI畸形错误

发布于 2025-02-10 14:48:53 字数 1793 浏览 0 评论 0原文

我最近有一个错误,当我尝试将节点服务器发送到以下查询搜索时:
!@#$%^&*()_+
我在镀铬上遇到了一个错误:

{status: 500, message: "URI malformed"}
message: "URI malformed"
status: 500

阅读后:
您应该使用suspaive而不是Encodeuri / encodeuricomponent?
javascript decodeuri(component)畸形的URI URI异常异常 任何方法可以在JavaScript中忽略某些字符中的EncodeUricompents? /a>
编码javascript
的百分比 通过a percent (%) sign in a url and get exact value of it using php
javascript decodeuri(component)畸形的uri uli异常extivion extivion extivion

我的代码仍然无法使用



for: !@#$%^&*()_+ when I wrap my string with encodeURIComponent and in the server do decodeURIComponent.
它也无法与Encodeurl一起使用。
如果我手动替换我会得到%2525,那不好。
Any idea how to solve it?
谢谢。

我的代码:

const endpoint = `${endpoint}&text=${encodeURIComponent(query)}`;
await fetch(endpoint);

I recently have a bug, when I try to send into my node server a query search of the following:
!@#$%^&*()_+
I get an error on my Chrome:

{status: 500, message: "URI malformed"}
message: "URI malformed"
status: 500

After reading:
When are you supposed to use escape instead of encodeURI / encodeURIComponent?
Javascript decodeURI(Component) malformed uri exception
any way of making encodeURIComponent in javascript ignore certain characters?
Percent encoding javascript
Pass a percent (%) sign in a url and get exact value of it using php
Javascript decodeURI(Component) malformed uri exception

My code still won't work for: !@#$%^&*()_+ when I wrap my string with encodeURIComponent and in the server do decodeURIComponent.
It also does not work with encodeURL.
If I do manually replace I get %2525 and it's not good.
Any idea how to solve it?
Thanks.

My code:

const endpoint = `${endpoint}&text=${encodeURIComponent(query)}`;
await fetch(endpoint);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伤感在游骋 2025-02-17 14:48:53

最终,我的服务器端有一个错误。我试图解码“%”符号。
通过以下内容解决了:

在客户端上:

const endpoint = `${endpoint}&text=${encodeURIComponent(query)}`;
await fetch(endpoint);

在服务器上:

decodeURIComponent(encodeURIComponent(query.text))

Eventually there was a bug on my server side. I tried to decode the '%' sign.
Solved it by the following:

On the client:

const endpoint = `${endpoint}&text=${encodeURIComponent(query)}`;
await fetch(endpoint);

On the server:

decodeURIComponent(encodeURIComponent(query.text))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文