【问题标题】:json response from httpwebresponse来自 httpwebresponse 的 json 响应
【发布时间】:2017-12-01 10:37:25
【问题描述】:

我在 httpwebresponse 中得到纯 json 响应,但无法在 htmldoc 或其他中得到它...

这里是代码..

public HtmlDocument Load(string url, string method)
    {
        Uri uri = new Uri(url);
        HtmlDocument doc;
        if ((uri.Scheme == Uri.UriSchemeHttps) ||
            (uri.Scheme == Uri.UriSchemeHttp))
        {
            doc = LoadUrl(uri, method, null, null);
        }
        else
        {
            if (uri.Scheme == Uri.UriSchemeFile)
            {
                doc = new HtmlDocument();
                doc.OptionAutoCloseOnEnd = false;
                doc.OptionAutoCloseOnEnd = true;
                if (OverrideEncoding != null)
                    doc.Load(url, OverrideEncoding);
                else
                    doc.DetectEncodingAndLoad(url, _autoDetectEncoding);
            }
            else
            {
                throw new HtmlWebException("Unsupported uri scheme: '" + uri.Scheme + "'.");
            }
        }
        if (PreHandleDocument != null)
        {
            PreHandleDocument(doc);
        }
        return doc;
    }

谁能告诉我如何从 httpwebresponse 获取文档上相同的 json 文本..

【问题讨论】:

  • Json 不是 Html。如果响应是json,那你为什么要使用HtmlAgilityPack?

标签: c# html-agility-pack


【解决方案1】:

我只是使用下面的代码并解决了我的问题...

 using (var streamReader = new StreamReader(resp.GetResponseStream()))
 {
       var result = streamReader.ReadToEnd();
       doc.LoadHtml(result.ToString());
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-16
    • 2016-08-06
    • 2017-09-24
    • 2017-09-25
    • 2019-02-09
    • 1970-01-01
    • 1970-01-01
    • 2015-11-24
    相关资源
    最近更新 更多