httpResponse.ResponseUri获取值中存在中文 获取后显示乱码 求指点 在线等!!!

bgaidu 2012-05-23 04:09:22
我定义了个获取代码如下:
////获取附件链接下载开始
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(MyLink);
request.Method = "GET";
request.Headers.Clear();
request.Headers[HttpRequestHeader.Cookie] = webBrowser1.Document.Cookie;
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:8080/myjsp/myprog/download.jsp?p=1230602
我通过以上代码 获取mydownurl得到真实地址,但是当真实地址中存在中文的时候 获取的地址显示为乱码 是这样的地址 http://www.*******.com:8080/myjsp/myfile/201205/2012052219344490750/2012Äê14-20ÈÕ½ðÈÚ°²È«ÔËÐп¼ºËÇé¿öͨ±¨.doc
而真正的地址为 http://www.*****.com:8080/myjsp/myfile/201205/2012052219344490750/2012年14-20日高法教科书.doc
求高手指点!!!!!!!!
...全文
461 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
bgaidu 2012-05-24
  • 打赏
  • 举报
回复
问题已经解决 抛出异常 在异常中查找需要的内容 谢谢大家!!!!
bgaidu 2012-05-23
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 cjh200102 的回复:]
对中文进行Encoding
[/Quote]
我这个主要问题是在于 HttpWebResponse httpResponse = (HttpWebResponse)request.GetResponse();当MyLink的真实地址中出现中文的时候,调试中运行到这句就报远程服务器返回错误: (404) 未找到。了,而且查看错误的详细信息 则看到 response 下的ResponseUri值为{http://www.*****.com:8080/myjsp/myfile/201205/2012052219344490750/2012Äê14-20ÈÕ½ðÈÚ°²È«ÔËÐп¼ºËÇé¿öͨ±¨.doc}
bgaidu 2012-05-23
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
楼主试着设置一下 HttpWebRequest.TransferEncoding
[/Quote]
我在 HttpWebResponse httpResponse = (HttpWebResponse)request.GetResponse();
之前增加了 request.SendChunked = true;
request.TransferEncoding = "gb2312"; 两句
但是运行的时候依然提示我 SendChunked 需要设置为 true 能否再给指点下
cjh200102 2012-05-23
  • 打赏
  • 举报
回复
对中文进行Encoding
theillusion 2012-05-23
  • 打赏
  • 举报
回复
楼主试着设置一下 HttpWebRequest.TransferEncoding
bgaidu 2012-05-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
设置编码
StreamReader sr = new StreamReader(resp.GetResponseStream(),Encoding.GetEncoding( "GB2312 "));
string source = sr.ReadToEnd();
[/Quote]
你这个必然是加载 HttpWebResponse httpResponse = (HttpWebResponse)request.GetResponse();
后 问题是 我程序运行到 HttpWebResponse httpResponse = (HttpWebResponse)request.GetResponse();
的时候碰到中文地址就报错了 不行啊
bgaidu 2012-05-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
设置编码
StreamReader sr = new StreamReader(resp.GetResponseStream(),Encoding.GetEncoding( "GB2312 "));
string source = sr.ReadToEnd();
[/Quote]
我是获取地址后 下载附件 我不需要读取链接具体文件的内容
EnForGrass 2012-05-23
  • 打赏
  • 举报
回复
设置编码
StreamReader sr = new StreamReader(resp.GetResponseStream(),Encoding.GetEncoding( "GB2312 "));
string source = sr.ReadToEnd();

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧