到Requestify每次调用,您可以通过一个Options
对象,该对象的定义描述如下:Requestify API Reference
您正在使用POST的short
方法,所以我会表明,第一,但这个同样的语法也适用于put
,请注意,get
,delete
,head
不接受数据参数,您通过params
config属性发送url查询参数。现在
requestify.post(url, data, config)
requestify.put(url, data, config)
requestify.get(url, config)
requestify.delete(url, config)
requestify.head(url, config)
,config
具有timeout
属性
超时为请求{数}
设置一个超时时间(毫秒)。
因此,我们可以用这种语法指定60秒的超时:
var config = {};
config.timeout = 60000;
requestify.post(url, data, config)
或内联:
requestify.post(url, data, { timeout: 60000 })
所以,现在让我们把它们一起到你的原始请求:
作为@Jabalaja指出,你应该捕获任何异常消息,howe你是否应该在延续中使用错误参数来做到这一点。 (.then
)
requestify.post('https://example.com/', {
email: '[email protected]'
}, {
timeout: 60000
})
.then(function(response) {
var answer = response.getBody();
console.log("answer:" + answer);
}, function(error) {
var errorMessage = "Post Failed";
if(error.code && error.body)
errorMessage += " - " + error.code + ": " + error.body
console.log(errorMessage);
// dump the full object to see if you can formulate a better error message.
console.log(error);
});