rogergao 2015-12-26 09:09 采纳率: 0%
浏览 2661
已结题

HttpWebResponse ResponseUri 跳转的URL中存在中文就乱码

C# 代码

                          string MyLink =  “http://www.zei8.net/plus/download.php?open=2&id=55507&uhash=dc74d5c3ccbb8856f2e13515”;
                                                        HttpWebRequest “request = (HttpWebRequest)WebRequest.Create(MyLink);
                            rettpWebRequest)WebRequest.Create(MyLink);quest.Method = "GET";
                            request.Headers.Clear();
                            request.ContentType = "application/x-www-form-urlencoded";
                            request.KeepAlive = true;
                            request.AllowAutoRedirect = true;


                            HttpWebResponse httpResponse = (HttpWebResponse)request.GetResponse();

                            string mydownurl = httpResponse.ResponseUri.ToString();
                            httpResponse.Close();

服务器端的情况无法控制,我们无法更改服务器端代码。

MyLink 为原始的地址
形式为 http://www.*******.com/plus/download.php?open=2&id=55507&uhash=dc74d5c3ccbb8856f2e13515
我通过以上代码 获取mydownurl得到真实地址,但是当真实地址中存在中文的时候 获取的地址显示为乱码 是这样的地址

http:///www.*******.com/2015/201502/Äê14-20ÈÕ½ðÈÚ°²È«ÔËÐп¼ºËÇé¿öͨ±¨.rar

实际地址是

http:///www.*******.com/2015/201502/《原来康熙》全集.rar

找了个测试地址

http://www.zei8.net/plus/download.php?open=2&id=55507&uhash=dc74d5c3ccbb8856f2e13515

  • 写回答

5条回答

  • ForHeartOnly 2015-12-26 09:13
    关注

    设置一下编码格式:方法:
    response:
    A、设置服务器端的编码
    response.setCharacterEncoding("utf-8”);
    B、通知浏览器服务器发送的数据格式
    response.setContentType("text/html;charset=utf-8”);
    C、浏览器使用utf-8进行解码

    request;
    A、post方式
    post方式属于表单提交,参数存在于请求体中。
    request.setCharacterEncoding("utf-8”)
    B
    在tomcat的server.xml中,设置元素的属性URIEncoding="UTF-8”即可。(默认没有设置此属性)

    评论

报告相同问题?

悬赏问题

  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法