2013-03-26 65 views
0

我有一些代码使用httpWebRequest发布数据,但是当我在引用中使用unicode文本时,它总是显示异常:“指定的值具有无效的控制字符。”httpWebRequest引用异常与unicode网址

  CookieContainer cookieContainer = new CookieContainer(); 
      HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
      httpWebRequest.Headers["Accept-Encoding"] = "gzip, deflate"; 
      httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate); 
      httpWebRequest.Timeout = this.Timeout; 
      httpWebRequest.CookieContainer = cookieContainer; 
      httpWebRequest.Method = method; 
      httpWebRequest.KeepAlive = this.KeepAlive; 
      httpWebRequest.ContentType = this.ContentType; 
      httpWebRequest.Accept = this.Accept; 
      httpWebRequest.UserAgent = this.UserAgent; 
      httpWebRequest.Referer = this.Referer; 
      httpWebRequest.ProtocolVersion = HttpVersion.Version11; 
      httpWebRequest.AllowAutoRedirect = true; 
      httpWebRequest.ServicePoint.Expect100Continue = false; 
      httpWebRequest.AllowWriteStreamBuffering = false; 
      httpWebRequest.Credentials = CredentialCache.DefaultCredentials; 
      httpWebRequest.Proxy = WebRequest.DefaultWebProxy; 

的网址是:somewhere.com/index?1yyezksvrgzkelork□=rgu{z5iihy5zvreiihy&1iutlomLork=gjsot5otjk~ 的Referer:somewhere.com/index?1yyezksvrgzkelork□=rgu{z5iihy5zvreiihy&1iutlomLork=gjsot5otjk~ 如果只使用URL它的正常运行。

回答

1

尝试使用HttpUtility.UrlEncode(...)编码您的引用程序(...)