Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.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
使用PowerShell触发Dropbox api saveurl get 400错误_Powershell_Dropbox Api - Fatal编程技术网

使用PowerShell触发Dropbox api saveurl get 400错误

使用PowerShell触发Dropbox api saveurl get 400错误,powershell,dropbox-api,Powershell,Dropbox Api,我正在按照此处编写我的powershell。这看起来很简单,但我只得到400个无效请求错误。我可以知道问题出在哪里,或者如何进一步排除故障吗?我对这400条信息一无所知。我用PowerShell和works测试了简单的上传文件。所以代币应该是好的 以下是我的PowerShell脚本: $token = Get-Content -Path "c:\token.txt" $authorization = "Bearer " + $token $headers = New-Object "System

我正在按照此处编写我的powershell。这看起来很简单,但我只得到400个无效请求错误。我可以知道问题出在哪里,或者如何进一步排除故障吗?我对这400条信息一无所知。我用PowerShell和works测试了简单的上传文件。所以代币应该是好的

以下是我的PowerShell脚本:

$token = Get-Content -Path "c:\token.txt"
$authorization = "Bearer " + $token
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", $authorization)
$headers.Add("Content-Type", 'application/json')

$body = @"
{
    "path": "/test.mp3",
    "url": "http://sxxxxx.com/today.mp3"
}
"@


    Invoke-RestMethod -Uri https://api.dropboxapi.com/2/files/save_url -Method Post -Headers $headers -Body $body

我的脚本将$body部分修改为以下内容:

$body = '{
    "path": "/test.mp3",
    "url": "http://sxxxxx.com/today.mp3"
}'

似乎我需要将参数作为字符串而不是json格式传递。

您已经注释掉了body
#-body$body
。没有它,这是一个无效的请求。@PalleDue我很抱歉。在发布到这里之前,我正在尝试调试。我已经测试了有身体和没有身体都有相同的结果。(我已经编辑了脚本)400是一个错误的输入参数。您是否从它返回的明文消息中获得了更多信息?是的,正如dschwartz0815所询问的,Dropbox API将在响应正文中返回更具体的错误消息。打印出来了解更多信息。我没有收到错误消息。也许我应该改进我的脚本以得到错误响应,但我不知道如何。