Are there any HTTP libraries in Powershell that is similar to Requests in Python or Mechanize in Ruby?
What I want is a PowerShell library that can easily send GET
, POST
requests and easily manage cookies between requests. Does this kind of library exists? Thanks.
I don't know either library you mention, but it sounds like something Invoke-WebRequest can do. You will need PowerShell v3 for that. Below is an example from the documentation of this command. Here and here are some other examples.
PS C:\> # Sends a sign-in request by running the Invoke-WebRequest cmdlet. The command specifies a value of "fb" for the SessionVariable parameter, and saves the results in the $r variable.
$r=Invoke-WebRequest http://www.facebook.com/login.php -SessionVariable fb
# Use the session variable that you created in Example 1. Output displays values for Headers, Cookies, Credentials, etc.
$fb
# Gets the first form in the Forms property of the HTTP response object in the $r variable, and saves it in the $form variable.
$form = $r.Forms[0]
# Pipes the form properties that are stored in the $forms variable into the Format-List cmdlet, to display those properties in a list.
$form | Format-List
# Displays the keys and values in the hash table (dictionary) object in the Fields property of the form.
$form.fields
# The next two commands populate the values of the "email" and "pass" keys of the hash table in the Fields property of the form. Of course, you can replace the email and password with values that you want to use.
$form.Fields["email"] = "[email protected]"
$form.Fields["pass"] = "P@ssw0rd"
# The final command uses the Invoke-WebRequest cmdlet to sign in to the Facebook web service.
$r=Invoke-WebRequest -Uri ("https://www.facebook.com" + $form.Action) -WebSession $fb -Method POST -Body $form.Fields
You seem to be looking for Invoke-WebRequest
(requires PowerShell v3).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With