【问题标题】:api fetching works in chrome brower, but doesn't work in terminal using "curl"api fetching 在 chrome 浏览器中工作,但在使用“curl”的终端中不起作用
【发布时间】:2021-11-25 14:55:56
【问题描述】:

我正在尝试使用open weather API,我刚刚创建了一个帐户并获得了我的 API 密钥,之后我写了 https://api.openweathermap.org/data/2.5/weather?q=London&appid=

在 zsh 中,它返回:

[1] 12567 zsh:未找到匹配项: https://api.openweathermap.org/data/2.5/weather?q=London jack@jackengtwistios-Mac-mini node-andrew % [1] + exit 1 curl https://api.openweathermap.org/data/2.5/weather?q=London

在 bash 中:

[1] 12715 jackengtwistios-Mac-mini:node-andrew jack$ {"cod":401, "message": "API 密钥无效。请参阅 http://openweathermap.org/faq#error401 了解更多信息。"}

但在 chrome 浏览器中它只返回预期的结果:

{"coord":{"lon":-0.1257,"lat":51.5085},"weather":[{"id":800,"main":"Clear","description":"clear 天空","icon":"01d"}],"base":"stations","main":{"temp":279.99,"feels_like":279.99,"temp_min":278.87,"temp_max":280.86, “压力”:1017,“湿度”:72},“能见度”:10000,“风”:{“速度”:0.45,“度”:331,“阵风”:2.24},“云”:{“所有":7},"dt":1637851503,"sys":{"type":2,"id":2019646,"country":"GB","sunrise":1637825718,"sunset":1637856008}," timezone":0,"id":2643743,"name":"London","cod":200}

【问题讨论】:

  • “无效的 API 密钥” - 您在 CURL 的哪个位置传递 api 密钥?

标签: api curl


【解决方案1】:

OP 显示此 URL 在 Chrome 中有效:

https://api.openweathermap.org/data/2.5/weather?q=London&appid=<--myapikey-->

但这就是 cURL 中使用的内容

curl https://api.openweathermap.org/data/2.5/weather?q=London

缺少appid参数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-23
    • 1970-01-01
    • 2014-06-27
    • 1970-01-01
    • 2021-04-07
    • 2017-05-07
    • 2012-10-23
    • 1970-01-01
    相关资源
    最近更新 更多