Я пытаюсь загрузить значения из приложения C # в скрипт PHP через POST, но скрипт 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);
в полях данных POST, которые содержат CDATA, но скрипт PHP по-прежнему не обрабатывает & amp;и & quot;должным образом.Например, передача строки
user=a&P&password=lol
даст
user=a
amp;P=
password=lol
вместо намеченного
user=a&P
password=lol