可能重复:
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。我该怎么做?
答案 0 :(得分:42)
在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"
答案 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")