tomcat6升级到7时400问题,以及url带有汉字时出错。

tomcat6升级到7时400问题:

在文件catalina.properties后加入tomcat.util.http.parser.HttpParser.requestTargetAllow=|。

tomcat7,url带有汉字时出错:

之前使用tomcat6,url带有汉字时没有问题,但是升级到7时,就出现一下错误,前台是winform,后台java。

Error parsing HTTP request header
Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
at org.apache.coyote.http11.InternalInputBuffer.parseRequestLine(InternalInputBuffer.java:194)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1052)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:662)

解决方案:把url内的中文转码成,GB2312,后台接收时,也用同样格式解码。

前台:

string url = p_sUrl;

for (int i = 0; i < url .Length; i++)
{
  if ((int)url [i] > 127)
  {
  String str = url [i].ToString();
  p_sUrl = p_sUrl.Replace(str, System.Web.HttpUtility.UrlEncode(str, Encoding.GetEncoding("GB2312")));
  }
}

try
{
  http.open("POST", p_sUrl, false, "", "");
  http.send(p_bStr);
}

后台:

request.setCharacterEncoding("GB2312");

 

posted @ 2018-11-12 17:39  菜鸟程序杜  阅读(1916)  评论(0编辑  收藏  举报