如何在PowerShell中使用HTTP GET? [重复]

时间:2022-09-23 07:43:00

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

可能重复:获取$ webclient.downloadstring以写入Powershell Powershell http文本中的文本文件,其中包含.cer for auth

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

我有一个SMS系统,使我能够从HTTP GET请求发送SMS:

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?

我想在PowerShell中输入文本的详细信息,然后浏览此URL。我该怎么做?

2 个解决方案

#1


36  

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

在PowerShell v3中,看一下Invoke-WebRequest和Invoke-RestMethod,例如:

$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"

#2


19  

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

下载Wget不是必需的; .NET Framework内置了Web客户端类。

$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")

#1


36  

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

在PowerShell v3中,看一下Invoke-WebRequest和Invoke-RestMethod,例如:

$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"

#2


19  

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

下载Wget不是必需的; .NET Framework内置了Web客户端类。

$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")