Why is PowerShell not able to send proper Crumb?

前端 未结 1 1273
天命终不由人
天命终不由人 2021-01-14 18:00

My PowerShell script:

$Params = @{
    uri     = \"http://${API_URL}:${API_Port}/crumbIssuer/api/json\";
    Method  = \'Get\';
    Headers = @{
        Auth         


        
1条回答
  •  滥情空心
    2021-01-14 18:26

    I modified the code as follows and it worked. Not sure though why previous code was throwing error.

    $API_User = "admin"
    $API_Pass = "password"
    $API_URL = "localhost"
    $API_Port = "8080"
    $API_Job = "test01"
    
    $h = @{}
    $h.Add('Authorization', 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$(${API_User}):$(${API_Pass})")))
    
    $Params = @{uri = "http://${API_URL}:${API_Port}/crumbIssuer/api/json";
            Method = 'Get';
            Headers = $h;}
    $API_Crumb = Invoke-RestMethod @Params
    
    $h.Add('Jenkins-Crumb', $API_Crumb.crumb)
    $Params['uri'] = "http://${API_URL}:${API_Port}/job/${API_Job}/build"
    $Params['Method'] = 'Post'
    $Params['Headers'] = $h
    
    Invoke-RestMethod @Params
    

    0 讨论(0)
提交回复
热议问题