Posting HTTP form without using ‘Invoke-WebRequest’

Question:

I have a working PowerShell 3.0 script that takes advantage of Invoke-WebRequest to post a form and save the respective raw HTML output. Unfortunately, the script doesn’t work on workstations with only PowerShell 2.0.

I was hoping someone could please help convert the below script to work with PowerShell 2.0 (without having to install PS modules, packages, or upgrade PowerShell). It looks like I need to use .NET webclient, but I’m not experienced enough to do this yet. A working example (based on my script) would be extremely appreciated!

PS: I’m using sls -pattern to filter out content in the raw HTML output. If there’s a more reliable way to identify certain items in the raw output, I wouldn’t mind seeing an example.

EDIT: Below, is my first attempt at getting the script to work. Anyway, it’s obviously not doing the same thing as my WORKING Invoke-WebRequest script above

Answer:

Here is the code I use to post my Web requests, this is not the exact answer, but I suppose you can adapt it :

Source:

Posting HTTP form without using ‘Invoke-WebRequest’ by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply