我必须使用Laravel和oauth2开发一个上传文件的API。我用邮递员测试了api并且工作正常。我还要写一个卷曲脚本。要获取令牌,请使用以下命令:
curl http://mysite/oauth/access_token -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=client_credentials&client_id=eeee59ddd3ed8ff3843839b&client_secret=aaaa6f8fa93d59c45502c0ae8c4a95b" -X POST
并收到
{
"access_token": "45ac1JvKsRNky25qnGpC28xAJGvckRXEkzq2a45",
"token_type": "Bearer",
"expires_in": 3600
}
执行命令后:
curl -v -H "Authorization: Bearer 45ac1JvKsRNky25qnGpC28xAJGvckRXEkzq2a45" -H "Content-Type: multiform/form-data" -F "file=@path_file" -F "access_token=45ac1JvKsRNky25qnGpC28xAJGvckRXEkzq2a45" -F "IdAdvertiser=5555555555" -X POST http://mysite/api/upload
curl -v -H "access_token: 45ac1JvKsRNky25qnGpC28xAJGvckRXEkzq2a45" -H "Content-Type: multiform/form-data" -F "file=@path_file" -F "IdAdvertiser=5555555555" -X POST http://mysite/api/upload
curl -v --request POST --url http://mysite/api/upload --header 'Cache-Control: no-cache' --header 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' --header 'Authorization: Bearer 45ac1JvKsRNky25qnGpC28xAJGvckRXEkzq2a45' --header 'Content-Type: application/json' --form 'file=@path_file' --form access_token=45ac1JvKsRNky25qnGpC28xAJGvckRXEkzq2a45 --form IdAdvertiser=55555555
在这种情况下,我总会收到同样的错误:
{"error":"invalid_request","error_description":"The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"access token\" parameter."}
感谢' S