我访问网站时试图获取cookie

时间:2016-11-09 17:53:35

标签: vb.net httpwebrequest webrequest httpwebresponse

我正在尝试访问一个网站,以便将cookie存储起来供以后使用,但是当我创建webrequest时,它不会发回任何cookie,但如果我在浏览器中查看它,请求会发送饼干。

我用来创建请求的代码:

        'get the cookie for the post request !important
        Dim req As HttpWebRequest = DirectCast(WebRequest.Create("http://www.dailymail.co.uk/home/index.html"), HttpWebRequest)
        req.Method = "GET"
        req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
        req.Host = "www.dailymail.com"
        req.CookieContainer = tmpcookie


        'get the cookie.
        Dim postcookie = DirectCast(req.GetResponse(), HttpWebResponse)
        tmpcookie.Add(postcookie.Cookies)

在我的提琴手中,当我访问该网站时,我得到以下信息:

enter image description here

当我通过webrequests创建请求时,我得到以下内容:

enter image description here

如您所见,没有发送任何Cookie。我怎样才能获得cookies?

0 个答案:

没有答案