日期:2014-05-17  浏览次数:20616 次

远程请求API xml 属性中有“+” 对方收到是空格
远程请求API xml 属性中有“+” 对方收到是空格

<abc type="abc+def">
 abc
</abc>

但是对方收到的是
<abc type="abc def">
 abc
</abc>

“+”变成了空格
一下是我的Http请求代码

  public static string PostXml(string url, string Method, string xml)
       {
           string ResponseResult = "";
           string para = "xml=" + xml;
           HttpWebRequest request = null;
           if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
           {
               ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
               request = WebRequest.Create(url) as HttpWebRequest;
               //request.ProtocolVersion = HttpVersion.Version10;
              
           }
           else
           {
               request = WebRequest.Create(url) as HttpWebRequest;//创建一个请求
               
           }
           request.KeepAlive = false;
           request.Method = Method;
           WebHeaderCollection webHead = new WebHeaderCollection();
           webHead.Add("Accept-Encoding:gzip,deflate");
           request.Headers = webHead;
           request.Accept = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
           request.ContentType = "application/x-www-form-urlencoded";
         
           Stream st = null;
           if (Method == "POST")
           {
              
               byte[] data = Encoding.UTF8.GetBytes(para);
               request.ContentLength = data.Length;
     &