I want to use the powershell to login the website: https://uk.blsspainvisa.com/visa4spain/login, I use my Chrome can open the website, while when I use the Invoke-WebRequest to login, I get the 403 error. Any one can help me? Thanks.
Asked
Active
Viewed 81 times
-1
-
Please post the code or error as text in your question, not an image. – toyota Supra Sep 01 '22 at 17:23
-
And Welcome to SO. SO has rules: [Provide MRE](https://stackoverflow.com/help/minimal-reproducible-example) --- [How to ask](https://stackoverflow.com/help/how-to-ask) --- [Don't ask](https://stackoverflow.com/help/dont-ask) --- [Proper Topic](https://stackoverflow.com/help/on-topic) --- [Why not upload images of code/errors?](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) --- [format your post properly](https://stackoverflow.com/help/formatting) – postanote Sep 02 '22 at 06:56
1 Answers
0
Putting this here, since it si too long for a normal comment.
Some sites actively block some, if not all automation efforts.
So, if this site is one of them, then this is not a PowerShell issue.
You also must use TLS for all SSL-based sites.
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Some sites, force you to go thru a landing page, and a quick test of the posted URL proves that out, as the case.
Pasting the exact URL you show in MSEdge, FF, Chrome, all present the Access Denied page. Why, because it's expecting stuff, from the previous page. Using the base URL, displays the landing page, where you must provide a country from the drop-down box first.
If you use Invoke-WebRequest on the base site, you will get denied as well,...
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri 'https://uk.blsspainvisa.com' -UseBasicParsing
Invoke-WebRequest : The remote server returned an error: (403) Forbidden.
At line:2 char:1
+ Invoke-WebRequest -Uri 'https://uk.blsspainvisa.com' -UseBasicParsing
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
...and thus all resources below it.

postanote
- 15,138
- 2
- 14
- 25