curl GET json API命令不起作用

时间:2017-07-31 17:50:18

标签: api curl

我似乎无法使用这个简单的curl API命令。原始示例代码使用HTML / Javascript。我使用Chrome运行代码,并使用开发人员工具记录会话。 html / js示例运行正常。我复制了chrome网络请求URL并将其插入curl命令,但没有运气。以下是Chrome“更多工具 - >开发者工具 - >网络 - >标题”给了我,

Request URL:https://api.betterdoctor.com/2016-03-01/doctors?location=37.773,-122.413,100&skip=2&limit=10&user_key=CODE_SAMPLES_KEY_9d3608187
Request Method:GET
Status Code:200 OK
Remote Address:52.9.169.107:443
Referrer Policy:no-referrer-when-downgrade

我尝试了以下curl命令,只是剪切并粘贴了chrome结果,

curl -k -H "Content-Type:application/json" -X GET https://api.betterdoctor.com/2016-03-01/doctors?location=37.773,-122.413,100&skip=2&limit=10&user_key=CODE_SAMPLES_KEY_9d3608187

我收到以下错误消息,

{"meta":{"error":true,"message":"Missing user_key","error_code":1000,"http_status_code":401}}'skip' is not recognized as an internal or external command,
operable program or batch file.
'limit' is not recognized as an internal or external command,
operable program or batch file.
'user_key' is not recognized as an internal or external command,
operable program or batch file.

任何想法我可能做错了什么?

1 个答案:

答案 0 :(得分:1)

man bash中,您会找到以下段落:

  

如果命令由控制操作符&终止,则shell在子shell中在后台执行命令。 shell不等待命令完成,返回状态为0.命令由a分隔;按顺序执行; shell等待每个命令依次终止。返回状态是最后执行的命令的退出状态。

为避免bash解释此运算符,您应在URL周围加上引号,使其成为字符串文字:

curl -k -H "Content-Type:application/json" -X GET "https://api.betterdoctor.com/2016-03-01/doctors?location=37.773,-122.413,100&skip=2&limit=10&user_key=CODE_SAMPLES_KEY_9d3608187"