如何在PowerShell中使用HTTP GET?

时间:2012-12-18 14:37:13

标签: http powershell http-get

  

可能重复:
  Get $webclient.downloadstring to write to text file in Powershell
  Powershell http post with .cer for auth

我有一个短信系统,可以让我从HTTP GET请求发送短信:

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

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

2 个答案:

答案 0 :(得分:42)

在PowerShell v3中,查看Invoke-WebRequestInvoke-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"

答案 1 :(得分:19)

下载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")