出現此原因的解決辦法其一,詳情可見:
https://www.cnblogs.com/dygrkf/p/9088370.html。
另一種解決方法,就是把url中不允許出現的字符編碼,后台接收時再解碼。
首先在tomcat7的目錄apache-tomcat-7.0.88\conf中修改文件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");