如何使用 curl 从 API 获取数据?

How to get data from API using curl?

(我是 curl 和 apigee 的新手)

我正在尝试从 API

获取 Body 数据

"https://staging.api.pearson.com/content/scapi/urn:pearson:manifestation:014f333d-ceda-476f-81f2-d3d6c89ace42"

通过以下命令使用 curl 但无法获取除错误字符串以外的任何数据

卷曲“https://staging.api.pearson.com/content/scapi/urn:pearson:manifestation:014f333d-ceda-476f-81f2-d3d6c89ace42

我得到的错误是:

{"fault":{"faultstring":"Failed to resolve API Key variable request.header.x-api key","detail":"errorcode":"steps.oauth.v2.FailedToResolveAPIKey"}}}

但是在浏览器中多次访问 URL 时,我可以根据需要获取 JSON 数据

CURL工作代码

curl "https://staging.api.pearson.com/content/scapi/urn:pearson:manifestation:014f333d-ceda-476f-81f2-d3d6c89ace42" -H "Accept:application/json"  -H "Accept-Encoding:gzip, deflate, sdch, br" -H "Accept-Language:en-US,en;q=0.8 " -H "Connection:keep-alive" -H "Host:staging.api.pearson.com" -H "X-ApiKey:7ij8zrLkCNR9DtAXx3KJ6yutoYnk4SAx" -H "X-PearsonSSOSession:AQIC5wM2LY4Sfczr6fmuhzvfN4dwnpK3c9K8tyduHkwg7sA.*AAJTSQACMDIAAlNLABQtNTk5Nzg3OTI1MTgxNTYxNjE3MAACUzEAAjAx*"

请有人建议获取JSON数据

抱歉,我是 curl 和 apigee 的新手

谢谢

curl "URL" \
 -H "Accept: application/json" \
 -H "x-apikey: {need to pass your API key here}" \
 -H "Content-Type: application/octet-stream"

将您的 x-apikey 放入{需要在此处传递您的 API 密钥}

正如您所说,在 chrome 中,它正在运行,请求成功后,您可以像下面那样复制 curl