长 json 字符串返回 err400 而较短的字符串则可以正常工作

发布于 2024-11-14 10:28:14 字数 2389 浏览 2 评论 0原文

我正在尝试将 json 字符串从客户端传递到服务器,我有一个 JSON.stringify 的数组,然后以如下所示的 url 发送到服务器:

http://localhost/sublimation/index.php/index/imgCreate/{"name":"pillow.png","element":"篮子ball-2.png","elAngle":0,"elTop":78,"elLeft":117,"elHeight":90,"elWidth":90,"captionA":"","capAR":0, “capAG”:200,“c apAB":200,"capATop":112,"capALeft":141,"capASize":12,"captionB":"","capBR":0,"capBG":200,"capBB":200,"capBTop “:11 2、"capBLeft":141、"capBSize":12、"照片":"#"、"picTop":0、"picLeft":0、"picHeight":20、"picWidth":110、"picAngle": 0}

现在返回错误 400 消息:

HTTP 错误 400。请求 URL 无效。

我设法让它工作的唯一方法是剪短绳子,其他任何方法都失败了。 因为它看起来 json 不是最流行的东西,因为我没有设法在谷歌上找到任何有帮助的东西。

有人有想法吗?

tnx, 伊多

编辑!!; 我已经根据建议编辑了代码,这就是我现在得到的:(仍然是相同的错误)

发布http://localhost/sublimation/index.php%2Findex%2FimgCreate%2F%7B%22name%22%3A%22pillow.png%22%2C%22element%22%3A%22amaut2.png% 22%2C%22el角度%22%3A0%2C%22el顶部%22%3A34%2 C%22elLeft%22%3A124%2C%22elHeight%22%3A90%2C%22elWidth%22%3A90%2C%22captionA%22%3A%22%22%2C% 22capAR%22%3A%220%22%2C%22capAG%22%3A%22%200%22%2C%22capAB%22%3A%22%200%22%2C%22capATop%22%3A 112%2C%22capALeft%22%3A141%2C%22capASize%22%3A%2212%22%2C%22captionB%22%3A%22%22%2C%22capBR% 22%3A%220%22%2C%22capBG%22%3A%22%200%22%2C%22capBB%22%3A%22%200%22%2C%22capBTop%22%3A112%2C%2 2capBLeft%22%3A141%2C%22capBSize%22%3A%2212%22%2C%22photo%22%3A%22%23%22%2C%22picTop%22%3A0% 2C%22picLeft%22%3A0%2C%22picHeight%22%3A20%2C%22picWidth%22%3A110%2C%22picAngle%22%3A0%7D 400(错误请求)

i'm trying to pass a json string from client to server, i have an array which is JSON.stringify-ed and then sent to server in a url which looks like this:

http://localhost/sublimation/index.php/index/imgCreate/{"name":"pillow.png","element":"basketball-2.png","elAngle":0,"elTop":78,"elLeft":117,"elHeight":90,"elWidth":90,"captionA":"","capAR":0,"capAG":200,"capAB":200,"capATop":112,"capALeft":141,"capASize":12,"captionB":"","capBR":0,"capBG":200,"capBB":200,"capBTop":112,"capBLeft":141,"capBSize":12,"photo":"#","picTop":0,"picLeft":0,"picHeight":20,"picWidth":110,"picAngle":0}

now that returns an error 400 msg:

HTTP Error 400. The request URL is invalid.

the only way i've managed to get it working was by cutting short the string, anything else failed.
as it looks json is not the most popular thing cause i didn't manage to find anything even remotely helpful on google.

does anyone have an idea?

tnx,
Ido

EDIT!!;
I've edited the code according to recommendations this is what i'm getting now: (still the same error)

POST http://localhost/sublimation/index.php%2Findex%2FimgCreate%2F%7B%22name%22%3A%22pillow.png%22%2C%22element%22%3A%22amaut2.png%22%2C%22elAngle%22%3A0%2C%22elTop%22%3A34%2C%22elLeft%22%3A124%2C%22elHeight%22%3A90%2C%22elWidth%22%3A90%2C%22captionA%22%3A%22%22%2C%22capAR%22%3A%220%22%2C%22capAG%22%3A%22%200%22%2C%22capAB%22%3A%22%200%22%2C%22capATop%22%3A112%2C%22capALeft%22%3A141%2C%22capASize%22%3A%2212%22%2C%22captionB%22%3A%22%22%2C%22capBR%22%3A%220%22%2C%22capBG%22%3A%22%200%22%2C%22capBB%22%3A%22%200%22%2C%22capBTop%22%3A112%2C%22capBLeft%22%3A141%2C%22capBSize%22%3A%2212%22%2C%22photo%22%3A%22%23%22%2C%22picTop%22%3A0%2C%22picLeft%22%3A0%2C%22picHeight%22%3A20%2C%22picWidth%22%3A110%2C%22picAngle%22%3A0%7D 400 (Bad Request)

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

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

发布评论

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

评论(3

浅听莫相离 2024-11-21 10:28:14

这当然不是一个有效的 URL,即使它更短。 URL 的路径段中不允许使用“、{、}、# 和 :”等字符。您必须对它们进行 URI 保护(“ 变为 %22 等)。也许您的浏览器会自动为您执行此操作,并且生成的 URL 达到了网络服务器的长度限制,然后返回 400。

使用 POST 请求应该可以解决该问题。与 URL 相比,您可以在那里传输更多的数据。

This is certainly not a valid URL even if it were shorter. Characters like ", {, }, # and maybe : are disallowed in the path segment of the URL. You have to URI-secape them (" becomes %22 and so on). Maybe your browser did that automatically for you, and the resulting URL hit a length limit of the webserver which then returned the 400.

Using POST requests should solve the problem. You can transfer much more data there than in a URL.

醉殇 2024-11-21 10:28:14

您需要对 json 进行编码,因为 json 中有一些特殊字符,如果它们在 url 中,它们就会进行交互。 可以提供帮助或提供线索。

问题也可能出在 # 上。

You need to encode your json, because you have some special chars in json that interact if they are in url. This could help or give a clue.

Problem also could be with #.

无需解释 2024-11-21 10:28:14

看起来您是通过 GET 而不是 POST 发送 JSON。 GET 太长会导致错误,并且容易出现问题。对 JSON 字符串进行编码也会有所帮助。

It looks like you're sending your JSON by GET instead of POST. Too long of a GET will cause errors, and is susceptible to problems. Encoding your JSON string will help as well.

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