Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use HTTP GET in PowerShell? [duplicate]

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 provides me the ability to send an 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?

like image 753
alex Avatar asked Dec 18 '12 14:12

alex


People also ask

How do I duplicate a file in PowerShell?

We can use PowerShell to copy a file from one location to another with the Copy-Item cmdlet. The location can be another local folder or a remote computer. Besides files, we can also copy complete folders with subfolders and content. And it's even possible to filter the files that we copy.

How do you repeat a PowerShell script?

Turns out the answer is fairly straight forward, wrap the command in a loop forever. This'll allow you to Ctrl-C out of it, and it'll keep repeating even after your command completes or otherwise exits the first time.

How does $_ work in PowerShell?

The “$_” is said to be the pipeline variable in PowerShell. The “$_” variable is an alias to PowerShell's automatic variable named “$PSItem“. It has multiple use cases such as filtering an item or referring to any specific object.

What is the function of get Servicestatus in PowerShell?

Get-Service gets all the services on the computer and sends the objects down the pipeline. The Where-Object cmdlet, selects only the services with a Status property that equals Running . Status is only one property of service objects. To see all of the properties, type Get-Service | Get-Member .


2 Answers

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" 
like image 138
Keith Hill Avatar answered Sep 20 '22 00:09

Keith Hill


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") 
like image 20
alroc Avatar answered Sep 21 '22 00:09

alroc