how to recreate a working CURL command with Invoke-WebRequest in Powershell

后端 未结 3 469
生来不讨喜
生来不讨喜 2020-12-28 20:27

This curl command works as desired:

curl -H \"X-Api-Key:j65k423lj4k2l3fds\" `
     -X PUT `
     -d \"alerts_enabled=true\" `
        https://some/working/fi         


        
3条回答
  •  一生所求
    2020-12-28 20:52

    got it to work natively using invoke-webrequest. powershell guru here at work helped me out. Switched to the New Relic API version 2 (available at https://rpm.newrelic.com/api/explore), which uses JSON instead of xml, and made some sytax tweaks.

    $json = @"{"alert_policy":[{"enabled":"true"}]"@
    
    $headers = @{}
    $headers["X-Api-Key"] = "j65k423lj4k2l3fds"
    
    Invoke-WebRequest -Uri "https://some/working/file.json" -Body $json -ContentType "application/json" -Headers $headers -Method Post
    

提交回复
热议问题