会发现content内容被截断了。想要获取完整的content:
ps> curl https://www.google.com | Select -ExpandProperty Content
3.2添加header
-Headers @{"accept"="application/json"}
3.3指定Method
-Method Get
3.4将获取到的content输出到文件
-OutFile 'c:Usersrmiaotempcontent.txt'
3.5表单提交
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
or
Invoke-RestMethod http://website.com/service.aspx -Body $R.Forms[0]
3.6内容筛选
PS C:Usersrmiao> $R = Invoke-WebRequest -URI http://www.bing.com?q=how+many+feet+in+a+mile
PS C:Usersrmiao> $R.AllElements | where {$_.innerhtml -like "*=*"} | Sort { $_.InnerHtml.Length } | Select InnerText -
First 5
innerText
---------
=
1
Next
=
3.7一个登陆示例
#发送一个登陆请求,声明一个sessionVariable 参数为fb, 将结果保存在$R
#这个变量FB就是header.cookie等集合
PS C:Usersrmiao> $R=curl http://www.facebook.com/login.php -SessionVariable fb
PS C:Usersrmiao> $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:Usersrmiao> $Form=$R.Forms[0]
PS C:Usersrmiao> $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:Usersrmiao> $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:Usersrmiao> $R.StatusDescription
OK
虽然没有curl那么主流,但一样可以成为http访问的一个选择。
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对易采站长站的支持。










