首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell中是否有类似于Python中的请求或Ruby中的Mechanize的HTTP库?

Powershell中是否有类似于Python中的请求或Ruby中的Mechanize的HTTP库?
EN

Stack Overflow用户
提问于 2013-09-05 04:06:31
回答 2查看 739关注 0票数 4

Powershell中是否有类似于Python中的请求或Ruby中的Mechanize的HTTP库?我想要的是一个PowerShell库,可以轻松地发送GETPOST请求,并轻松管理请求之间的cookies。这种库存在吗?谢谢。

EN

回答 2

Stack Overflow用户

发布于 2013-09-05 04:44:13

你提到的两个库我都不知道,但听起来像是Invoke-WebRequest可以做的事情。为此,您需要使用PowerShell v3。下面是来自此命令的documentation的示例。Herehere是其他一些例子。

代码语言:javascript
复制
PS C:\> # Sends a sign-in request by running the Invoke-WebRequest cmdlet. The command specifies a value of "fb" for the SessionVariable parameter, and saves the results in the $r variable.

$r=Invoke-WebRequest http://www.facebook.com/login.php -SessionVariable fb

# Use the session variable that you created in Example 1. Output displays values for Headers, Cookies, Credentials, etc. 

$fb

# Gets the first form in the Forms property of the HTTP response object in the $r variable, and saves it in the $form variable. 

$form = $r.Forms[0]

# Pipes the form properties that are stored in the $forms variable into the Format-List cmdlet, to display those properties in a list. 

$form | Format-List

# Displays the keys and values in the hash table (dictionary) object in the Fields property of the form.

$form.fields

# The next two commands populate the values of the "email" and "pass" keys of the hash table in the Fields property of the form. Of course, you can replace the email and password with values that you want to use. 

$form.Fields["email"] = "User01@Fabrikam.com"
$form.Fields["pass"] = "P@ssw0rd"

# The final command uses the Invoke-WebRequest cmdlet to sign in to the Facebook web service. 

$r=Invoke-WebRequest -Uri ("https://www.facebook.com" + $form.Action) -WebSession $fb -Method POST -Body $form.Fields
票数 6
EN

Stack Overflow用户

发布于 2013-09-05 04:41:30

您似乎正在寻找Invoke-WebRequest (需要PowerShell v3)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18622845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档