100分求助 HttpWebResponse 返回的Headers内location带有中文的编码问题
100分求助 HttpWebResponse 返回的Headers内location带有中文的编码问题
或 Content-Disposition带有中文的都不能正确识别
和某位朋友的该帖http://topic.csdn.net/t/20050531/21/4049901.html大致一样,但大家都是说发送的url的编码问题,其实不是这样
给出一个地址
http://www.yuleye.com/mirror/attachment.php?aid=1 浏览器打开后能识别出中文名: 中文名附件.jpg
但是在.net里用
myPostRequest = (HttpWebRequest)HttpWebRequest.Create(this._strUrl);//创建myPostRequest
myPostRequest.CookieContainer = new CookieContainer();//cookie容器,
myPostRequest.Referer = this.refUrl;
myPostRequest.Accept = "*/*";
myPostRequest.AllowAutoRedirect = false;
myPostRequest.ContentType = "application/octet-stream";
myPostRequest.Method = "GET";
........
/*
myPostRequest.Headers["Accept-Language"]= "zh-cn";
myPostRequest.Headers["Accept-Encoding"]= "gzip, deflate";
myPostRequest.Headers["Accept-Charset"]= "gb2312";
myPostRequest.Headers["Content-Language"]= "zh-cn";
myPostRequest.Headers["Content-Encoding"]= "gzip";
*/
this.encoding = System.Text.Encoding.GetEncoding("GB2312"); //试过UTF8 Default编码
//myPostRequest.CookieContainer.Add(this.cookiePost); 加过cookie
HttpWebResponse hwr = null;
string sLoca = "";
hwr = (HttpWebResponse)myPostRequest.GetResponse();
sLoca = hwr.Headers["Location"];
for (int ss = 0; ss < hwr.Headers.Count; ss++)
{
System.Console.WriteLine(hwr.Headers.Keys[ss]+" : "+hwr.Headers[hwr.Headers.Keys[ss]]);
}
string attstr = hwr.Headers["Content-Disposition"]; //这里正确的应该是 attachement; filename=中文名附件.jpg
但返回的是 attachement; filename=?D????t.jpg 这样的字符串 同样的问题也会出现在其他Headers里,比如上面提到的帖子里的hwr.Headers["Location"];
请问各位怎么解决,困扰好久了,可能涉及到编码 和urlencode的地方基本上试过了,请哪位给出代码测试成功了 我给全分