powershell httpwebrequest GET method cookiecontainer problem?

后端 未结 3 1552
时光取名叫无心
时光取名叫无心 2020-12-15 11:11

I\'m trying to scrape a website that has user authentication. I am able to do a POST to send my login and stores a cookie. However, after the login I get a 403 error when tr

3条回答
  •  没有蜡笔的小新
    2020-12-15 11:19

    I found that since cookies can have additional information attached (like the URL or HTTP-only), the $res.Headers["Set-Cookie"] didn't work for me. But using your $CookieContainer variable, you can easily change it to use GetCookieHeader(url), which will strip out the extra information and leave you with a properly formatted cookie string:

    $web = new-object net.webclient
    $web.Headers.add("Cookie", $CookieContainer.GetCookieHeader($url))
    $result = $web.DownloadString($url)
    

提交回复
热议问题