是不是HttpWebRequest自己的问题

bytepark 2003-05-29 03:45:52
您好:
如下代码:

1.工程示例代码:
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri("http://localhost/test.asp?code=中国", true));
HttpWebResponse webRes = (HttpWebResponse)webReq.GetResponse();
StreamReader readStream = new StreamReader( webRes.GetResponseStream(), Encoding.GetEncoding("GB2312"));
string strHtml = readStream.ReadToEnd();

2.TEST.ASP代码:
<html>
<body>
<%
Response.Write Request.QueryString("code")
%>
</body>
</html>

我发现:
不论Uri的构造函数是否已转义定义为TRUE还是FALSE,返回的信息都不正确,但是在浏览器中却是正确的。
不知道什么原因,希望您能够给予指导,谢谢!!!
...全文
30 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
coollzh 2003-05-29
  • 打赏
  • 举报
回复
System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("gb2312");
StringBuilder sb = new StringBuilder();
sb.Append("http://www.youdomain.com?");
sb.Append ("name=");
sb.Append(HttpUtility.UrlEncode(this.txtName.Text,encoder));
sb.Append("&content1=");
sb.Append(HttpUtility.UrlEncode(this.txtContent.Text,encoder));
HttpWebRequest request= (HttpWebRequest)WebRequest.Create(sb.ToString());
cmsoft 2003-05-29
  • 打赏
  • 举报
回复
"http://localhost/test.asp?code="+Server.UrlEncode("中国"),true

110,534

社区成员

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

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

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