Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Invoke-WebRequest : You must write ContentLength bytes to the request stream before calling [Begin]GetResponse

$
0
0

Hi,

Am trying to execute the following script in my  windows power shell, but keep running into this error.

Can somebody help please?

$c1=$args[0]
$path=$args[1]
$cert=$args[2]
$p=$args[3]
$peid=$args[4]
$a2="AccountFN"


$body6="{`"provider`": {`"href`":`""+$path+"/providers/1`"},`"id`": `"$peid`",`"name`": `“"+$a2+"`”,`"description`": `“"+$a2+"`”}"

$r=Invoke-WebRequest -uri "$path/tenants/$c1/projects/$p/accounts" -Headers $headers -Certificate $cert -ContentType application/json -Method POST -Body $body6

Am using the Invoke-WebRequst to call an API which has both credential based authentication and SSL based authentication.

Am i doing something wrong?

Error Obtained:

Invoke-WebRequest : You must write ContentLength bytes to the request stream before calling [Begin]GetResponse.At C:\Windows\Temp\PO_WorkingDir_a432e8d1-d685-45e2-926d-351440a713ff\PO_PSScript_a432e8d1-d685-45e2-926d-351440a713ff.ps1:16 char:4+ $r=Invoke-WebRequest -uri "$path/tenants/$c1/projects/$p/accounts" -Headers $hea ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (:) [Invoke-WebRequest], ProtocolV    iolationException    + FullyQualifiedErrorId : System.Net.ProtocolViolationException,Microsoft.    PowerShell.Commands.InvokeWebRequestCommand


Roney Varghese ACP


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>