How to use HTTP GET in PowerShell?


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?

This question is tagged with http powershell http-get

~ Asked on 2012-12-18 14:37:13

The Best Answer is


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"

~ Answered on 2012-12-18 15:57:46


Downloading Wget is not necessary; the .NET Framework has web client classes built in.

$wc = New-Object system.Net.WebClient;
$sms = Read-Host "Enter SMS text";
$sms = [System.Web.HttpUtility]::UrlEncode($sms);
$smsResult = $wc.downloadString("http://smsserver/SNSManager/msgSend.jsp?uid&to=smartsms:*+001XXXXXX&msg=$sms&encoding=windows-1255")

~ Answered on 2012-12-18 15:04:15

Most Viewed Questions: