Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 调用RestMethod Powershell V3内容类型_Json_Rest_Powershell - Fatal编程技术网

Json 调用RestMethod Powershell V3内容类型

Json 调用RestMethod Powershell V3内容类型,json,rest,powershell,Json,Rest,Powershell,我能够使用powershell v5中的JIRA rest API。但是,相同的代码在powershell v3中抛出以下错误 WARNING: Remote Server Response: The 'Content-Type' header must be modified using the appropriate property or method. 源代码 $basicAuth = "Basic " + [System.Convert]::ToBase64String([Syste

我能够使用powershell v5中的JIRA rest API。但是,相同的代码在powershell v3中抛出以下错误

WARNING: Remote Server Response: The 'Content-Type' header must be modified using the appropriate property or method.
源代码

$basicAuth = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($Username):$Password"))
    $headers = @{
        "Authorization" = $basicAuth
        "Content-Type"="application/json"
    }

 $response = Invoke-RestMethod -Uri $requestUri -Method POST -Headers $headers -Body $body

Invoke Restmethod有一个-ContentType参数,因此错误似乎表明您应该使用它来指定内容类型,而不是通过headers参数传递它:

$basicAuth = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($Username):$Password"))
    $headers = @{
        "Authorization" = $basicAuth
    }

 $response = Invoke-RestMethod -Uri $requestUri -Method POST -Headers $headers -Body $body -ContentType 'application/json'

Invoke Restmethod有一个-ContentType参数,因此错误似乎表明您应该使用它来指定内容类型,而不是通过headers参数传递它:

$basicAuth = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($Username):$Password"))
    $headers = @{
        "Authorization" = $basicAuth
    }

 $response = Invoke-RestMethod -Uri $requestUri -Method POST -Headers $headers -Body $body -ContentType 'application/json'