创建您自己的 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())
{
// ...
}