【发布时间】:2016-08-21 01:29:33
【问题描述】:
我正在学习使用 API。我正在尝试进行 api 调用,例如:
curl -X POST https://api.locu.com/v2/venue/search -d '{
"api_key" : "f165c0e560d0700288c2f70cf6b26e0c2de0348f",
"fields" : [ "name", "location", "contact" ],
"venue_queries" : [
{
"name" : "bistro central parc"
}
]
}'
这适用于 curl,但我想在没有 cURL 的情况下拨打电话。我将使用来自节点的请求来执行此操作,但是我现在只想使用邮递员进行呼叫。我试过了:
https://api.locu.com/v2/venue/search?api_key={myAPIKey}&fields=["name","location","contact"]&venue_queries=[{name="bistro%20central%20parc"}]
但是我得到了不允许的 405 方法。我显然以错误的方式看待这个问题。这不是格式化 http 请求的正确方法吗?
在 javascript 中是这样的:
var request = require('request');
request('https://api.locu.com/v2/venue/search?api_key={myAPIKey}&fields=["name","location","contact"]&venue_queries=[{name="bistro%20central%20parc"}]', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Print the google web page.
}
})
或者是否有更好的方法来构建选项?
【问题讨论】:
-
我认为这不可能,原始请求是使用 POST 方法发送的,如果您无法控制服务器,则不会有任何等效的 GET 方法。您需要能够更改服务器行为才能做到这一点。
标签: javascript api curl request