Powershell invoke-webrequest not working

心已入冬 提交于 2019-12-05 18:17:47

[Turning my comment into an answer]

In Windows PowerShell, Invoke-WebRequest uses the Internet Explorer engine for parsing websites, unless you tell it not to. IE has a lot of restrictions - coming from its security model of Trusted Sites/security zones, IE Enhanced Security, overrides by Group Policy, maybe more, and it looks like you'd tried everything else sensible, and it was worth trying to test that directly.

This switch:

Invoke-WebRequest -UseBasicParsing ....

avoids the IE engine and makes a HTTP request and processes the response all within C#/.Net.

The trade-off is that you get plain text results to work with and can't access the page through the HTML DOM, no getElementByTagName() or anything that needs a live browser engine to work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!