如下创建您自己的URL编码算法; WebRequest方法将使用您为自定义编码提供的URI。
string input = "http://www.example.com/q?Ö=æ";
StringBuilder sb = new StringBuilder();
foreach (byte by in Encoding.GetEncoding("ISO-8859-1").GetBytes(input))
{
// NOTE: This is very simplistic; a robust solution would probably really need
// to handle all non-alphanum and non-reserved characters, as specified by
// http://www.ietf.org/rfc/rfc2396.txt
if (by <= 0x7F)
sb.Append((char) by);
else
sb.Append(string.Format("%{0:X2}", by));
}
Uri uri = new Uri(sb.ToString());
// uri.AbsoluteUri == "http://www.example.com/q?%D6=%E6"
WebRequest request = WebRequest.Create(uri);
using (request.GetResponse())
{
// ...
}
你目前使用什么方法对它们进行编码? – 2010-11-11 12:11:08
目前没有,这是给我们的问题,因为.net似乎默认为UTF-8。 – Grubsnik 2010-11-11 12:50:36