开发者

long json string returns err400 while shorter string works fine

开发者 https://www.devze.com 2023-03-11 19:21 出处:网络
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:

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%20开发者_运维百科0%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)


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.


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 #.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消