如何使用-d参数发送curl更新请求? [英] How to send curl update request with -d parameter?
问题描述
我需要使用 box API参考寻求帮助(我正在查看更新用户
部分,但遇到了一些麻烦:
I need to send a curl request from powershell, using box api reference for help (I'm looking the the section called Update User
, but I'm having some trouble:
curl https://api.box.com/2.0/users/11111 -H @{"Authorization" = "token"} -d '{"name": "bob"}' -X PUT
应更新用户名,但我得到:
Should update the user's name, but I get:
Invoke-WebRequest:找不到一个接受参数'{ name: bob}'的位置参数。 \IT\bassie\Box\GetUsers.ps1:5 char:1
+ curl https://api.box.com/2.0/users/892861590 -H @ { Authorization = ...
+ ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
+ CategoryInfo:InvalidArgument:(:) [Invoke-WebRequest],参数erBindingException
+ FullyQualifiedErrorId:PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Invoke-WebRequest : A positional parameter cannot be found that accepts argument '{"name": "bob"}'. At G:\IT\bassie\Box\GetUsers.ps1:5 char:1 + curl https://api.box.com/2.0/users/892861590 -H @{"Authorization" = " ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
我尝试将其重新排列为
-d @{"name" = "bob"}
,但错误更改为
Invoke-WebRequest:找不到位置参数,接受参数 System.Collections.Hashtable。
在G:\IT\bassie\Box\GetUsers.ps1:5 char:1
+ curl https://api.box.com/2.0/users/892861590 -H @ { Authorization = ...
+ ~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
+ CategoryInfo:InvalidArgument:(:) [Invoke-WebRequest],ParameterBindingException
+ FullyQualifiedErrorId:PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Invoke-WebRequest : A positional parameter cannot be found that accepts argument 'System.Collections.Hashtable'. At G:\IT\bassie\Box\GetUsers.ps1:5 char:1 + curl https://api.box.com/2.0/users/892861590 -H @{"Authorization" = " ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
我需要在 -d
参数中添加什么?
What do I need to put into the -d
parameter?
推荐答案
我设法用
$url = "https://api.box.com/2.0/users/111111111"
$headers = @{"Authorization" = "Bearer TOKEN"}
$body = '{"status": "inactive"}'
$contentType = "application/json"
Invoke-WebRequest $url -Headers $headers -ContentType $contentType -Body $body -Method PUT
因此,似乎不仅需要替换 -D
参数和 -Body
,但我还必须将 ConteType
指定为 application / json
以便使用该格式。
So it seems that not only did I need to replace the -D
parameter with -Body
, but I also had to specify the ConteType
as application/json
in order to use that format.
这篇关于如何使用-d参数发送curl更新请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!