如何使用Invoke-WebRequest发布请求

时间:2017-01-19 15:50:06

标签: powershell

我如何使用Invoke-WebRequest发布所有这些参数

POST /token HTTP/1.1
Host: login.huddle.net
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&client_id=s6BhdRkqt&redirect_uri=MyAppServer.com/receiveAuthCode&code=i1WsRn1uB

2 个答案:

答案 0 :(得分:5)

以下是如何将该主体转换为PowerShell可以解释的主体。

$body = @{grant_type='authorization_code'
      client_id='s6BhdRkqt'
      redirect_uri='MyAppServer.com/receiveAuthCode'
      code='i1WsRn1uB'}
$contentType = 'application/x-www-form-urlencoded' 
Invoke-WebRequest -Uri <yourUrl> -body $body -ContentType $contentType

答案 1 :(得分:0)

做那样的事

$loginPage = Invoke-WebRequest "http:\\website.com\" # invoke login form page
$loginForm = $loginPage.Forms[0] # Get the form to fill
$loginForm.fields["userName"] = "usrnm" # fill the username
$loginForm.fields["password"] = "psswd" # fill the password
$loginPage = Invoke-WebRequest -Uri ("http:\\website.com\") -Method POST -Body $loginForm.fields # Post the form to log-in