tomcat7以上的版本,400BadRequest

出现此原因的解决办法其一,详情可见:

https://www.cnblogs.com/dygrkf/p/9088370.html。

另一种解决方法,就是把url中不允许出现的字符编码,后台接收时再解码。

首先在tomcat7的目录apache-tomcat-7.0.88conf中修改文件server.xml,

在<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/>

加入useBodyEncodingForURI="true" URIEncoding="GB2312"GB2312,编码类型自己决定)。

然后在前台编码:

string p_sUrlCopy = p_sUrl;
for (int i = 0; i < p_sUrlCopy.Length; i++)
{
  int j = (int)p_sUrlCopy[i];
  if (j > 127 || j == 34 ||j == 91 || j == 93 || j == 123 || j == 124 || j == 125)// 数字代表什么可以百度找ascii码对照表
  {
    String str = p_sUrlCopy[i].ToString();

    // 把字符转换,url进行编码

    p_sUrl = p_sUrl.Replace(str, System.Web.HttpUtility.UrlEncode(str, Encoding.GetEncoding("GB2312")));
  }
}
object l_ReturnObject = null;
try
{
  http.open("POST", p_sUrl, false, "", "");
  http.send(p_bStr);
}

后台解码:

request.setCharacterEncoding("GB2312");

原文地址:https://www.cnblogs.com/dulianyong/p/10019412.html