c# - WebClient c# 使用\n 发送帖子而不换行

标签 c# webclient

我尝试发送一个包含\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/

相关文章:

c# - 在特定于 ASP .NET MVC 5.1/HTML 5 中显示日期时间选择器而不是日期选择器

c# - 在 Windows 窗体中为 Font 调用 dispose()

c# - 将 MEF 与 MVC 结合使用

c# - 远程服务器 (403) 使用 WebClient 时出现禁止错误

java - 在 WebClient 中处理异常抛出 io.netty.handler.timeout.ReadTimeoutException

c# - 如何向 WebClient (C#) 添加证书?

c# - 如何反序列化 JSON 并将其映射到字符串对象

c# - 自定义通用集合 - 重构它的最佳方法是什么?

spring-boot - Spring Boot 通过 WebClient 将文件从一个 api 传递/上传到另一个 api

java - Web 客户端中的 ClassCastException