【发布时间】:2016-11-18 21:36:55
【问题描述】:
我有这个脚本可以成功登录网站并执行查询:
$credential = Get-Credential
$postParams = @{username=$credential.UserName;password=$credential.GetNetworkCredential().password}
Invoke-WebRequest -Uri http://www.nexusmods.com/newvegas/sessions/?Login -Method POST -Body $postParams -SessionVariable cookie
$query = Invoke-WebRequest -Uri http://www.nexusmods.com/newvegas/mods/searchresults/? -WebSession $cookie
我想做的是在另一个网站 Trello 上做类似的事情。这是脚本:
$credential = Get-Credential
$postParams = @{method='password';'factors[user]'=$credential.UserName;'factors[password]'=$credential.GetNetworkCredential().password}
Invoke-WebRequest -Uri https://trello.com/1/authentication -Method POST -Body $postParams -SessionVariable cookie
$result = Invoke-WebRequest -uri https://trello.com/ -WebSession $cookie
但是,结果变量显示一个页面,就好像用户没有登录一样,所以我假设会话没有正确保存。我该如何解决这个问题?
【问题讨论】:
-
你想用 Trello 做什么?他们有一个 API,比尝试通过他们的网页登录要容易得多。如果你告诉我你想做什么,我可以提供帮助。
-
我正在编写将使用 API 的 PowerShell 脚本,但它希望我不想将我的密钥或任何令牌硬编码到其中,也不想强迫任何使用该脚本的人拥有记住这样的事情。所以我的目标是使用 webrequests 登录网站并获取帐户的 API 密钥并生成令牌,这样使用 API 的脚本只需从 CLI 获得凭据。
-
我使用他们的 API 编写了一个本地执行此操作的方法,如果有帮助请告诉我。
标签: powershell trello