请求HTTP页面时URL自动使用UTF-8编码的问题

rovoboy 2003-05-14 02:13:37
在使用HttpWebRequest的时候我发送了一个含有中文的URL,但是在提交请求的时候系统把这个中文变成了UTF-8编码于是在IIS的LogFile中就是以下一条记录:
03:30:30 172.16.8.64 GET /Autis SQL=select%20*%20from%20contactt%20where%20A04%20like%20'%25%E7%94%B2dd%25'%20for%20xml%20auto&root=root 200

但SQLServer并不将UTF-8编码变回原来的中文,也就是说原来是查询含有"甲dd"的语句却变成了查询含有"%E7%94%B2dd"的语句。

请各位指教如何使系统发送URL的时候不以UTF-8形式发送。

另外有一点奇怪,IE是可以的,但IE高级选项里面的“始终以UTF-8编码发送URL”却是钩上的。这是IE发送的请求在IIS日志里面的记录,可以看出只有中文UTF-8编码的区别
03:31:15 172.16.8.64 GET /Autis SQL=select%20*%20from%20contactt%20where%20A04%20like%20'%25甲dd%25'%20for%20xml%20auto&root=root 200

另外,VC6里面Ctrl+Alt+T是列出成员,Ctrl+Shift+Space是参数信息,VS.Net环境中这两个的快捷键是什么,或者怎么修改,每次都要用右键菜单太不爽。


System.Uri MyUri=new Uri("http://172.16.8.64/Autis?SQL=select%20*%20from%20contactt%20where%20A04%20like%20'%25甲dd%25'%20for%20xml%20auto&root=root");
// HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://172.16.8.64/Autis?SQL=select * from contactt where A04 like '%25甲dd%25' for xml auto&root=root");
Response.Write(MyUri);
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(MyUri);
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
// Gets the stream associated with the response.
Stream receiveStream = myHttpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader(receiveStream, encode );
Char[] read = new Char[256];
// Reads 256 characters at a time.
int count = readStream.Read( read, 0, 256 );
while (count > 0)
{
// Dumps the 256 characters on a string and displays the string to the console.
String str = new String(read, 0, count);
Response.Write(str);
count = readStream.Read(read, 0, 256);
}
// Releases the resources of the response.
myHttpWebResponse.Close();
// Releases the resources of the Stream.
readStream.Close(); }
...全文
430 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
rovoboy 2003-05-16
  • 打赏
  • 举报
回复
自己UP
rovoboy 2003-05-14
  • 打赏
  • 举报
回复
Web.Config我改过了,没用。

我知道可以变回来,但我这个Url请求的是我无法控制的一个程序,是SQL Server处理的,我怎么变回来啊!所以只能在请求的时候用GB2312格式。
visualcpu 2003-05-14
  • 打赏
  • 举报
回复
你可以在web.config文件里改编码格式呀!另外,它将中文变成UTF-8编码,你也可以把它变回中文呀!

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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