本文介绍了HANDELING饼干和标题与agilitypack C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

agilitypack确实非常出色,我在HTML解析,但对于其他HTML方面?对象agilitypack.HtmlWeb允许访问cookie和头?

agilitypack does excellent job for me in html parsing,but what about other html aspects?the object agilitypack.HtmlWeb allow access to cookies and headers?

推荐答案

访问cookie和头可以通过 HtmlWeb。preRequest获得 HtmlWeb.PostResponse 处理程序。执行HTTP请求之前出现的第一个。一个HTTP请求已经被执行后,会出现第二个。要使用cookie,你应该通过设置 HtmlWeb.UseCookies 属性启用一个 HtmlWeb 实例真正的

Access to the cookies and headers could be obtained through HtmlWeb.PreRequest and HtmlWeb.PostResponse handlers. The first one occurs before an HTTP request is executed. The second one occurs after an HTTP request has been executed. To use cookies you should enable it for an HtmlWeb instance by setting HtmlWeb.UseCookies property to true.

下面是一个例子:

var web = new HtmlWeb { UseCookies = true };
web.PreRequest += request =>
{
    // gets access to the cookie container
    var cookieContainer = request.CookieContainer;
    //  gets access to the request headers
    var headers = request.Headers;
    return true;
};
web.PostResponse += (request, response) =>
{
    // response headers
    var headers = response.Headers;
    // cookies
    var cookies = response.Cookies;
};

这篇关于HANDELING饼干和标题与agilitypack C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 18:02