为什么WebClient DownloadString返回\ r \ n?

时间:2015-09-23 20:53:45

标签: xml rest serialization

我正在尝试反序列化它,我认为所有\ 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;
}

1 个答案:

答案 0 :(得分:0)

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