过去,当我将内容从我的 C# 应用程序上传到网站时,我使用了如下 POST 请求:
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://" + this.server + "/log.php");
wr.Method = "POST";
wr.ContentType = "application/x-www-form-urlencoded";
string paramString = "v=" + this.version + "&m=" + this.message;
wr.ContentLength = paramString.Length;
StreamWriter stOut = new StreamWriter(wr.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(paramString);
stOut.Close();
我的问题是,现在我的情况是 this.message
很可能包含换行符、制表符和特殊字符,包括“&”和“=”。我需要转义这个内容吗?如果是,怎么办?
最佳答案
您可以根据需要使用 HttpUtility.HtmlEncode/HtmlDecode 或 UrlEncode/UrlDecode。
关于C# HttpWebRequest - 转义 POST 内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/770355/