请求HTTP页面时URL自动使用UTF-8编码的问题
在使用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(); }