我正在尝试在我的 PUT
中使用 REST API
方法,但我认为我有语法问题。到目前为止,这就是我所拥有的:
$url3 = "example.com"
$contentType3 = "application/json"
$basicAuth3 = get_token
$headers3 = @{
Authorization = $basicAuth3
};
$data = @{
userId = "_39_1";
courseId = "_3_1";
availability = {
available = "Yes"
};
courseRoleId = "Student"
};
$json = $data | ConvertTo-Json;
Invoke-RestMethod -Method PUT -Uri $url3 -ContentType $contentType3 -Headers $headers3 -Body $json;
我不认为
Invoke-RestMethod
能够读取 $json
变量,这就是为什么它给我一个错误。有什么建议么?我得到的错误如下:
最好的,
最佳答案
您必须创建另一个哈希表以提高可用性。您错过了可用性对象的 @
之前的 {
。
$url3 = "myurl";
$contentType3 = "application/json"
$basicAuth3 = get_token
$headers3 = @{
Authorization = $basicAuth3
};
$data = @{
userId = "_39_1";
courseId = "_3_1";
availability = @{
available = "Yes"
};
courseRoleId = "Student"
};
$json = $data | ConvertTo-Json;
Invoke-RestMethod -Method PUT -Uri $url3 -ContentType $contentType3 -Headers $headers3 -Body $json;
关于powershell - Invoke-RestMethod REST API PUT 方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43051357/