2011-08-30 87 views
0

我试图通过POST将C#应用程序的值上传到PHP脚本,但是php脚本似乎忽略了转义实体。在C中使用HttpRequest发送CDATA到PHP的问题#

public static Stream GetStream(string postData, string file) 
     { 
      try 
      { 
      HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create(remoteServer + "/" + file + "?"); 

      //ASCIIEncoding encoding = new ASCIIEncoding(); 
      UTF8Encoding encoding = new UTF8Encoding(); 
      byte[] data = encoding.GetBytes(postData); 

      HttpWReq.Method = "POST"; 
      HttpWReq.ContentType = "application/x-www-form-urlencoded"; 
      HttpWReq.ContentLength = data.Length; 
      HttpWReq.AllowAutoRedirect = false; 

      Stream newStream = HttpWReq.GetRequestStream(); 
      newStream.Write(data, 0, data.Length); 
      newStream.Close(); 
      //Get the response handle, we have no true response yet! 
      HttpWebResponse WebResp = (HttpWebResponse)HttpWReq.GetResponse(); 
      //Let's show some information about the response 
      Console.WriteLine(WebResp.StatusCode); 
      Console.WriteLine(WebResp.Server); 
      Console.WriteLine(WebResp.ResponseUri.ToString()); 

      //Now, we read the response (the string), and output it. 
      Stream Answer = WebResp.GetResponseStream(); 
      return Answer; 
     } 
     catch (WebException ex) 
     { 
      MessageBox.Show(ex.ToString()); 
      return null; 
     } 
    } 

我打电话

System.Net.WebUtility.HtmlEncode(content); 
在包含CDATA但PHP脚本仍然不处理&放大器POST数据领域

;和&“正常。例如,传递字符串

user=a&P&password=lol 

会产生

user=a 
amp;P= 
password=lol 

而不是预期的

user=a&P 
password=lol 

回答