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");
總結
以上是生活随笔為你收集整理的tomcat6升级到7时400问题,以及url带有汉字时出错。的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: Subversion安装和使用
- 下一篇: http,socket,进程通信,网络通
