HttpWebRequest 有关 uri 的编码问题
利用 http analyzer 抓包的URL
http://www.qidian.com/BookReader/DivAuthorTipping.aspx?bookId=1321104&authorId=1648617&authorName=%u71d5%u5f52%u6881
我的代码如下
string myUri = "http://www.qidian.com/BookReader/DivAuthorTipping.aspx?bookId=1321104&authorId=1648617&authorName=%u71d5%u5f52%u6881";
HttpWebRequest myHttpWebRequest12 = (HttpWebRequest)WebRequest.Create(myUri);
if (IsNeedProxy)
myHttpWebRequest12.Proxy = proxy;
myHttpWebRequest12.Timeout = 500000;
myHttpWebRequest12.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/x-silverlight, */*";
myHttpWebRequest12.Referer = strUrl + strUser2;
myHttpWebRequest12.Headers.Add("Accept-Language", "zh-cn");
myHttpWebRequest12.Headers.Add("Accept-Encoding", "gzip, deflate"); //add by King Lao
myHttpWebRequest12.Headers.Add("Cache-Control", "no-cache");
myHttpWebRequest12.ContentType = "application/x-www-form-urlencoded ";
myHttpWebRequest12.ContentLength = indata1.Length;
myHttpWebRequest12.Method = "POST";
myHttpWebRequest12.CookieContainer = myCookieContainer;
myHttpWebRequest12.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; MAXTHON 2.0)";
Stream myRequestStream12 = myHttpWebRequest12.GetRequestStream();
StreamWriter myStreamWriter12 = new StreamWriter(myRequestStream12, Encoding.GetEncoding("gb2312"));
myStreamWriter12.Write(indata1);
myStreamWriter12.Close();
myRequestStream12.Close();
HttpWebResponse myHttpWebResponse12 = (HttpWebResponse)myHttpWebRequest12.GetResponse();
Stream myResponseStream12 = myHttpWebResponse12.GetResponseStream();
StreamReader myStreamReader12 = new StreamReader(myResponseStream12, Encoding.GetEncoding(myHttpWebResponse12.CharacterSet));
outdata = myStreamReader12.ReadToEnd();
myHttpWebResponse12.Close();
myStreamReader12.Close();
myResponseStream12.Close();
程序出错,用http analyzer 抓我自己的程序,发现url变成了
http://www.qidian.com/BookReader/DivAuthorTipping.aspx?bookId=1321104&authorId=1648617&authorName=%25u71d5%25u5f52%25u6881
请各位大侠给指教。
[解决办法]
string strUri = "http://www.qidian.com/BookReader/DivAuthorTipping.aspx?bookId=1321104&authorId=1648617&authorName=%u71d5%u5f52%u6881";
Uri myUri = new Uri(strUri );
strUri = myUri.ToString();
HttpWebRequest myHttpWebRequest12 = (HttpWebRequest)WebRequest.Create(strUri );
已经解决。