How to use HTTP GET in PowerShell?

alex picture alex · Dec 18, 2012 · Viewed 121k times · Source

Possible Duplicate:
Get $webclient.downloadstring to write to text file in Powershell
Powershell http post with .cer for auth

I have an SMS system that provide me the ability to send SMS from an HTTP GET request:

http://smsserver/SNSManager/msgSend.jsp?uid&to=smartsms:*+001XXXXXX&msg="text of the message"&encoding=windows-1255

I want to enter the details to the text from PowerShell and just surf to this URL. How can I do it?

Answer

Keith Hill picture Keith Hill · Dec 18, 2012

In PowerShell v3, have a look at the Invoke-WebRequest and Invoke-RestMethod e.g.:

$msg = Read-Host -Prompt "Enter message"
$encmsg = [System.Web.HttpUtility]::UrlEncode($msg)
Invoke-WebRequest -Uri "http://smsserver/SNSManager/msgSend.jsp?uid&to=smartsms:*+001XXXXXX&msg=$encmsg&encoding=windows-1255"