【问题标题】:Why is WebClient DownloadString returning \r\n?为什么 WebClient DownloadString 返回 \r\n?
【发布时间】:2015-09-23 20:53:45
【问题描述】:

我正在尝试反序列化它,我认为所有的 \r\n 到处都是问题。

知道这是关于什么的吗?

    //   static string baseUrl = "http://service.leads360.com/ClientService.asmx/GetLastModifiedLead?username=xxx&password=xxx";

        using (WebClient webClient = new WebClient())
        {
        //    webClient.Encoding = Encoding.UTF8;
         //   webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            string result = webClient.DownloadString(baseUrl);
            return result;
        }

 public static Stream ToStream(this string @this)
{
    var stream = new MemoryStream();
    var writer = new StreamWriter(stream);
    writer.Write(@this);
    writer.Flush();
    stream.Position = 0;
    return stream;
}

public static T ParseXML<T>(this string @this) where T : class
{
    var reader = XmlReader.Create(@this.Trim().ToStream(), new XmlReaderSettings() { ConformanceLevel = ConformanceLevel.Document });
    return new XmlSerializer(typeof(T)).Deserialize(reader) as T;
}

【问题讨论】:

  • 下载字符串不会操纵内容。这必须存在于正在下载的内容中。只需将它们替换为string.empty
  • 好的。我会试试的。奇怪的是我没有发现其他人有同样的问题。

标签: xml rest serialization


【解决方案1】:

我是个假人,调用了错误的服务,所以问题只是试图序列化对象。我在调试器中看到了 \r\n 并认为这是原因

【讨论】:

    猜你喜欢
    • 2012-06-02
    • 2015-10-02
    • 2013-11-03
    • 2014-07-20
    • 2016-06-23
    • 2015-10-21
    • 2020-06-30
    • 1970-01-01
    • 2023-04-05
    相关资源
    最近更新 更多