PS> Get-Alias -Definition Invoke-WebRequest | Format-Table -AutoSize CommandType Name Version Source ----------- ---- ------- ------ Alias curl -> Invoke-WebRequest Alias iwr -> Invoke-WebRequest Alias wget -> Invoke-WebRequest
Gets content from a web page on the Internet.
Parameter Set: Default
Invoke-WebRequest [-Uri] <Uri> [-Body <Object> ] [-Certificate <X509Certificate> ] [-CertificateThumbprint <String> ] [-ContentType <String> ] [-Credential <PSCredential> ] [-DisableKeepAlive] [-Headers <IDictionary> ] [-InFile <String> ] [-MaximumRedirection <Int32> ] [-Method <WebRequestMethod> {Default | Get | Head | Post | Put | Delete | Trace | Options | Merge | Patch} ] [-OutFile <String> ] [-PassThru] [-Proxy <Uri> ] [-ProxyCredential <PSCredential> ] [-ProxyUseDefaultCredentials] [-SessionVariable <String> ] [-TimeoutSec <Int32> ] [-TransferEncoding <String> {chunked | compress | deflate | gzip | identity} ] [-UseBasicParsing] [-UseDefaultCredentials] [-UserAgent <String> ] [-WebSession <WebRequestSession> ] [ <CommonParameters>]
PS C:\Users\rmiao> curl -URi https://www.google.com
StatusCode : 200
StatusDescription : OK
Content : <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many speci..."
RawContent : HTTP/1.1 200 OK
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alt-Svc: quic=":443"; ma=2592000; v="36,35,34,33,32"
Vary: Accept-Encoding
Transfer-Encoding: chunked
ps> curl https://www.google.com | Select -ExpandProperty Content
-Headers @{"accept"="application/json"}
-Method Get
-OutFile 'c:\Users\rmiao\temp\content.txt'
For example: $R = Invoke-WebRequest http://website.com/login.aspx $R.Forms[0].Name = "MyName" $R.Forms[0].Password = "MyPassword" Invoke-RestMethod http://website.com/service.aspx -Body $R
Invoke-RestMethod http://website.com/service.aspx -Body $R.Forms[0]
PS C:\Users\rmiao> $R = Invoke-WebRequest -URI http://www.bing.com?q=how+many+feet+in+a+mile
PS C:\Users\rmiao> $R.AllElements | where {$_.innerhtml -like "*=*"} | Sort { $_.InnerHtml.Length } | Select InnerText -
First 5
innerText
---------
=
1
Next
=
#发送一个登陆请求,声明一个sessionVariable 参数为fb, 将结果保存在$R
#这个变量FB就是header.cookie等集合
PS C:\Users\rmiao> $R=curl http://www.facebook.com/login.php -SessionVariable fb
PS C:\Users\rmiao> $FB
Headers : {}
Cookies : System.Net.CookieContainer
UseDefaultCredentials : False
Credentials :
Certificates :
UserAgent : Mozilla/5.0 (Windows NT; Windows NT 6.3; en-US) WindowsPowerShell/4.0
Proxy :
MaximumRedirection : -1
#将response响应结果中的第一个form属性赋值给变量Form
PS C:\Users\rmiao> $Form=$R.Forms[0]
PS C:\Users\rmiao> $Form.fields
Key Value
--- -----
lsd AVqQqrLW
display
enable_profile_selector
isprivate
legacy_return 0
profile_selector_ids
return_session
skip_api_login
signed_next
trynum 1
u_0_0
u_0_1
lgnrnd 214945_qGeg
lgnjs n
email
pass
persistent
default_persistent 1
# 查看form
PS C:\Users\rmiao> $Form | Format-List
Id : login_form
Method : post
Action : /login.php?login_attempt=1&lwv=100
Fields : {[lsd, AVqQqrLW], [display, ], [enable_profile_selector, ], [isprivate, ]...}
#查看属性
$Form.fields
#设置账号密码
$Form.Fields["email"] = "User01@Fabrikam.com"
$Form.Fields["pass"] = "P@ssw0rd"
#发送请求并保存结果为$R
$R=Invoke-WebRequest -Uri ("https://www.facebook.com" + $Form.Action) -WebSession $FB -Method POST -Body $Form.Fields
#查看结果
PS C:\Users\rmiao> $R.StatusDescription
OK
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有