zoukankan      html  css  js  c++  java
  • 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");

  • 相关阅读:
    BiLiBiLi爬虫
    12-UE4-控件类型
    11-UE4-UMG UI设计器
    10-UE4-蓝图定义简介
    UE4-目录结构简介
    UE4-字符串
    UE4-基类
    Redis-事物
    Redis的主从配置
    Redis持久化-AOF
  • 原文地址:https://www.cnblogs.com/dulianyong/p/10019412.html
Copyright © 2011-2022 走看看