我尝试发送一个包含\n 的 json,但是当我发送它时,webclient 会进行换行,其中\n 是我想要发送的示例:
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.Accept] = "*/*";
wc.Headers[HttpRequestHeader.AcceptLanguage] = "en-US,en;q=0.5";
wc.Headers[HttpRequestHeader.AcceptEncoding] = "deflate";
wc.Headers[HttpRequestHeader.ContentType] = "application/json";
ServicePointManager.Expect100Continue = false;
string textToSend = "This is a Test\n This is a Test2"
string sendString = textToSend;
byte[] responsebytes = wc.UploadData("https://localhost/", "POST",
System.Text.Encoding.UTF8.GetBytes(sendString));
string sret = System.Text.Encoding.UTF8.GetString(responsebytes);
}
输出:这是一个测试 这是一个测试2
我怎样才能让它输出:这是一个测试\n这是一个测试2?
最佳答案
尝试转义,传递 \\n
而不是 \n
。那是你要的吗?尝试使用Regex.Escape
关于c# - WebClient c# 使用\n 发送帖子而不换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48934869/