Wrong encoding on PowerShell Invoke-WebRequest POST

前端 未结 2 452
难免孤独
难免孤独 2020-12-15 08:11

I\'m using Invoke-WebRequest POST method to send an text data. After sending the text in a wrong encoding.

Script:

$postData = \"žluťoučký kůň úpěl ď         


        
2条回答
  •  渐次进展
    2020-12-15 08:49

    I had to do two things to solve the problem. Encode the body and add the charset to the header:

    $body = [System.Text.Encoding]::UTF8.GetBytes($body);
    
    $headers = @{
                "Content-Type"="application/json; charset=utf-8";
                "OData-MaxVersion"="4.0";
                "OData-Version"="4.0";
            };
    
    Invoke-WebRequest -Uri "$($odataEndpoint)systemusers($userid)" -Method PATCH -Headers $headers -Body $body -UseDefaultCredentials
    

提交回复
热议问题