HERE 将 REST apis returns web ui 放在 json 上
HERE places REST apis returns web ui instead on json
我正在评估 HERE 地点 API。但是,url 会 return 网页而不是普通的 JSON 作为响应。示例查询:
https://places.cit.api.here.com/places/v1/autosuggest?app_id={YOUR_APP_ID}&app_code{YOUR_APP_CODE}&at=52.5304417,13.4111201&q=rest&pretty
我需要简单的回复 JSON,但在 documentation page 上找不到任何信息。
您必须设置 Accept
header 以便服务在 JSON 中响应。
参见文档中的示例 here:
curl \
-X GET \
-H 'Accept: application/json' \
--get 'https://places.demo.api.here.com/places/v1/discover/search' \
--data-urlencode 'at=37.7942,-122.4070' \
--data-urlencode 'q=restaurant' \
--data-urlencode 'app_id={YOUR_APP_ID}' \
--data-urlencode 'app_code={YOUR_APP_CODE}'
答案是在url中添加回调参数。示例:
https://places.cit.api.here.com/places/v1/autosuggest?app_id={YOUR_APP_ID}&app_code{YOUR_APP_CODE}&at=52.5304417,13.4111201&q=rest&pretty&callback=xyz
文档中并不清楚。我从 HERE 支持那里获得了这些信息。
这是因为您尝试从 浏览器地址栏 发出请求,在这种情况下,浏览器会自动将 Accept: text/html
添加到请求 headers ⁽¹⁾.
然后,因为 Places API 有一些网络帮助工具可以使用可用参数,它 returns html(网络 UI)因为 Accept: text/html
在请求中找到 headers.
添加 callback
的解决方案更像是一种解决方法,因为它使用回调参数的值包装响应。
您最初的请求实际上是有效的。如果你从你的程序或像 Postman 这样的 REST 客户端而不是从浏览器发送它,你实际上默认得到 JSON,所以没有更多的事情要做。当然可以显式发送headerAccept: application/json
以防万一
[1]打开浏览器开发者工具的网络面板,看看发送了什么。
我正在评估 HERE 地点 API。但是,url 会 return 网页而不是普通的 JSON 作为响应。示例查询:
https://places.cit.api.here.com/places/v1/autosuggest?app_id={YOUR_APP_ID}&app_code{YOUR_APP_CODE}&at=52.5304417,13.4111201&q=rest&pretty
我需要简单的回复 JSON,但在 documentation page 上找不到任何信息。
您必须设置 Accept
header 以便服务在 JSON 中响应。
参见文档中的示例 here:
curl \
-X GET \
-H 'Accept: application/json' \
--get 'https://places.demo.api.here.com/places/v1/discover/search' \
--data-urlencode 'at=37.7942,-122.4070' \
--data-urlencode 'q=restaurant' \
--data-urlencode 'app_id={YOUR_APP_ID}' \
--data-urlencode 'app_code={YOUR_APP_CODE}'
答案是在url中添加回调参数。示例:
https://places.cit.api.here.com/places/v1/autosuggest?app_id={YOUR_APP_ID}&app_code{YOUR_APP_CODE}&at=52.5304417,13.4111201&q=rest&pretty&callback=xyz
文档中并不清楚。我从 HERE 支持那里获得了这些信息。
这是因为您尝试从 浏览器地址栏 发出请求,在这种情况下,浏览器会自动将 Accept: text/html
添加到请求 headers ⁽¹⁾.
然后,因为 Places API 有一些网络帮助工具可以使用可用参数,它 returns html(网络 UI)因为 Accept: text/html
在请求中找到 headers.
添加 callback
的解决方案更像是一种解决方法,因为它使用回调参数的值包装响应。
您最初的请求实际上是有效的。如果你从你的程序或像 Postman 这样的 REST 客户端而不是从浏览器发送它,你实际上默认得到 JSON,所以没有更多的事情要做。当然可以显式发送headerAccept: application/json
以防万一
[1]打开浏览器开发者工具的网络面板,看看发送了什么。