[英]Use curl with default credential
我想將 curl 與默認憑據一起使用,然后我不需要將我的機密信息放入代碼中。 可能嗎?
這就是代碼應該是這樣的:
$a = curl UseDefaultCredentials -method POST ....
(無需輸入 -u 用戶名:密碼)
在 PowershellCore v7 之前,curl 是 Invoke-WebRequest 的別名。
Get-Alias -Definition Invoke-WebRequest |
Format-Table -AutoSize
# Results
<#
CommandType Name Version Source
----------- ---- ------- ------
Alias curl -> Invoke-WebRequest
Alias iwr -> Invoke-WebRequest
Alias wget -> Invoke-WebRequest
#>
PowerShell IVR(又名 curl)有一個憑證參數。
因此,如果您想使用真正的 curl.exe,那么您必須使用該擴展名,否則,PowerShell 命令首選項會接管。
about_Command_Precedence - PowerShell | 微軟文檔
如果不指定路徑,PowerShell 在為當前 session 中加載的所有項目運行命令時使用以下優先順序:
別名 Function Cmdlet 外部可執行文件(程序和非 PowerShell 腳本)
因此,如果您鍵入“help”,PowerShell 首先查找名為 help 的別名,然后查找名為 Help 的 function,最后查找名為 Help 的 cmdlet。 它運行它找到的第一個幫助項。
因此,請參閱有關如何使用 cmdlet 的幫助文件,
# Get specifics for a module, cmdlet, or function
(Get-Command -Name Invoke-WebRequest).Parameters
(Get-Command -Name Invoke-WebRequest).Parameters.Keys
# Results
<#
...
Credential
...
#>
Get-help -Name Invoke-WebRequest -Examples
# Results
<#
$R = Invoke-WebRequest -URI http://www.bing.com?q=how+many+feet+in+a+mile
$R.AllElements | where {$_.innerhtml -like "*=*"} | Sort { $_.InnerHtml.Length } | Select InnerText -First 5
the shortest HTML value often helps you find the most specific element that matches that text.
$R=Invoke-WebRequest http://www.facebook.com/login.php -SessionVariable fb
$FB
$Form = $R.Forms[0]
$Form | Format-List
$Form.fields
$Form.Fields["email"]="User01@Fabrikam.com"
$R=Invoke-WebRequest -Uri ("https://www.facebook.com" + $Form.Action) -WebSession $FB -Method POST -Body $Form.Fields
# Sends a sign-in request by running the Invoke-WebRequest cmdlet. The command specifies a value of "fb" for the SessionVariable parameter, and saves
$R.StatusDescription
(Invoke-WebRequest -Uri "http://msdn.microsoft.com/en-us/library/aa973757(v=vs.85).aspx").Links.Href
#>
Get-help -Name Invoke-WebRequest -Full
Get-help -Name Invoke-WebRequest -Online
或指定擴展名並使用 curl.exe 的命令行選項。
至於在 PowerShell 中使用憑證安全性,這在web中是一個有據可查的事情,有幾個選項。 MS powershellgallery.com 中有用於憑證管理和用例的模塊。
Find-Module -Name '*credential*' |
Format-Table -AutoSize
# Results
<#
Version Name Repository Description
------- ---- ---------- -----------
2.0 CredentialManager PSGallery Provides access to credentials in the Windows Credential Manager
...
1.0.11 pscredentialmanager PSGallery This module allows management and automation of Windows cached credentials.
...
1.1.7 CredentialStore PSGallery CredentialStore saves powershell credentials securely to file
...
1.0.0 CredentialLocker PSGallery CredentialLocker is a module that provides commandlets to manage credentials in the password vault....
...
1.1 CredentialsManager PSGallery The module Credentials Manager provides you with convenient and safe way to store your credentials ...
...
1.1.0 PSCredentialTools PSGallery PSCredentialTools provides various methods for securely storing and retrieving credentials used in ...
...
1.0.477 PSCredentialStore PSGallery A simple credential manager to store and reuse multiple credential objects.
...
#>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.