2017-07-31 79 views
0

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

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命令,只是剪切和粘贴的镀铬效果,

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. 

任何想法我可能是做错了?

+0

尝试在引号 '卷曲-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“ – Josh

回答

1

man bash,你会发现以下段落:

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

为了避免bash解释这个操作符,你应该把引号您的网址,以使其成为一个字符串文字:

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" 
+0

你是对的!我在https附近引用了引号,它完美地工作。很好的解释... – skmansfield