状态码: 400 / Bad Request解决方案
最编程
2024-01-16 10:32:31
...
今天做项目的时候,需要向服务器接口 传递 json参数
请求 URL: http://localhost:8080/zjmarket55/gridturnpage?action=refresh&pk=-1&condition=aCondition%3D{"REQUEST_NAME":"1"}%26cond1%3D%257b%2522REQUEST_NAME%2522:%25221%2522%257d&tmpPercentWidth=1666&localcache=table&url_source=XMLHTTP
请求方法: POST
状态码: 400 / Bad Request
原因:
HttpGet或 HttpPost都不能传包含 ” 、“{“、”}”这样的参数,需要对特殊字符进行转义,把 ” 转成%22,把 { 转成%7b,把 } 转成%7d
JSONObject paramJson = new JSONObject();
paramJson.put("serviceType", "plat");
JSONObject queryData= new JSONObject();
queryData.put("name", google+"");
queryData.put("url", www.google.com+"");
paramJson.put("queryData", queryData);
Gson gson = new Gson();
String gsonStr = paramJson.toString();
//特殊字符进行转义
gsonStr = gsonStr.replace("\"", "%22")
.replace("{", "%7b").replace("}", "%7d");
推荐阅读
-
搞定!Http状态码406(不可接受)错误的解决方案
-
总结了导致HTTP请求状态码为400的原因
-
前端与后端存在哪方面问题导致400状态码的出现?
-
HTTP 400状态码背后的原因是什么?
-
个人总结:解读HTTP状态码的400\500错误代码
-
解决HTML 400状态码和HTTP 400 Bad Request状态码的方法
-
HTTP状态码:400\500 错误代码(个人总结)
-
【JavaWeb】探讨HTTP状态码100、200、300、400、500、600的解析
-
http statusCode(状态码) 200、300、400、500序列
-
常见的HTTP状态码(400 / 404 / 500)解析