powershell http post REST API basic authentication

后端 未结 4 555
甜味超标
甜味超标 2020-12-13 20:17

I have basic authentatication working with REST API using curl:

curl -X POST  -H \'Accept: application/json\' -u user:password http://localhost/test/
         


        
4条回答
  •  失恋的感觉
    2020-12-13 20:28

    I know this is an old thread, but for those who might stumble across this the invoke-restmethod is a much better, and simpler, vehicle for making API calls with PowerShell.

    Build a parameter list as a hash table:

    $params = @{uri = 'https:/api.trello.com/1/TheRestOfYourURIpath';
                       Method = 'Get'; #(or POST, or whatever)
                       Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($acctname):$($password)"));
               } #end headers hash table
       } #end $params hash table
    
    $var = invoke-restmethod @params
    

    Your parameter hash table may differ slightly.

    I actually haven't gotten this to work with Trello, but I have with GitHub, Serena Business Manager and Jira.

提交回复
热议问题