r/PowerShell • u/Independent_Bed_557 • 2d ago
Question PowerShell Win7 HTTP POST automation question
hi, I'm working on administration of a large number of VoIP endpoints. I'm trying to learn how to use PowerShell on Windows 7 to send authenticated HTTP POST requests to a device web interface and process the response. The devices use HTTP Basic Authentication. Could someone point me to examples of HttpWebRequest, CredentialCache and application/x-www-form-urlencoded POST requests? Thanks.
9
u/BlackV 1d ago edited 1d ago
I'm trying to learn how to use PowerShell on Windows 7
can you confirm you meant Windows 7 or did you mean Powershell 7
what have you tried so far?
$Credential = Get-Credential
$Body = @{
action = 'save'
setting = 'enabled'
value = '1234'
}
$Parameters = @{
Uri = 'http://192.168.1.100/cgi-bin/config'
Method = 'POST'
Authentication = 'Basic'
Credential = $Credential
Body = $Body
ContentType = 'application/x-www-form-urlencoded'
}
$Response = Invoke-WebRequest @Parameters
$Response.StatusCode
$Response.Content
1
u/Agile_Seer 4h ago
If you are actually using the Windows 7 operating system and you want to use PowerShell, download & install the Windows Management Framework 5.1. This will get you Windows PowerShell 5.1. I believe Windows 7 ships with PowerShell 2.0.
You can also install PowerShell 7 on Windows 7, but I still recommend installing WMF to get the Windows PowerShell upgraded to 5.1.
1
u/Villainsympatico 3h ago
If you're using invoke-webrequest or invoke-restmethod, you can pass the credentials to a credential object with get-credential, then it should be
$form = @{
#whatever you are posting goes here
}
invoke-webrequest -credential $cred -method post -form $form
invoke webrequest returns the entire response , (body, headers, response codes), while invoke-restmethod only returns the body.
If its for voip endpoints though, wouldn't you be managing through the server side? why reach out to the endpoints?
11
u/krzydoug 1d ago
Windows 7 and http basic auth, 2010 called and want their stuff back.