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

时间:2017-06-08 12:27:26

标签: curl apigee apigee-baas apigee127

(我是卷曲的,也是新朋友)

我正在尝试从API获取Body数据

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

使用curl with following命令但无法获取除故障字符串

之外的任何数据

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数据

enter image description here

CURL woking code

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数据

对不起我是新来的卷曲和apigee

由于

2 个答案:

答案 0 :(得分:2)

enter image description here

正如您所说,在Chrome中,它正在运行,根据成功的请求,您可以像下面那样复制卷曲

答案 1 :(得分:0)

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密钥}