我正在尝试使用 Meteor.http.call 发送短信。我遇到两个错误:
First error:When page loaded,"WebSocket connection to 'ws://localhost:3000/sockjs/632/i0uapg48/websocket' failed: WebSocket is closed before the connection is established."
Second error:when I click ebultenkydet,"Uncaught TypeError: Cannot read property 'call' of undefined"
Template.footerLayout.events({
'click #ebultenkaydet': function(e, template) {
var auth_url="http://api.sorentesms.com/index.php"
var result = Meteor.http.call("POST", auth_url, {
data: {
'apiNo':'1',
'user':'test',
'pass':'test123',
'message':'hi',
'number':'+905075587***',
'from':'test',
},
headers: {
"content-type":"application/json",
"Accept":"application/json"
},
})
}
});
你能帮我解决一下吗? 谢谢大家
最佳答案
您正在客户端 block 内发送 http 请求,并且 Meteor.http
仅在服务器端可用。您必须将此 block 放入 Meteor.isServer block 中。
不要忘记meteor添加http
才能使用代码:
让我重写你的代码:
if (Meteor.isServer) {
Meteor.methods({
authCall: function () {
this.unblock(); // Make sure server doesn't get block from this call
var auth_url="http://api.sorentesms.com/index.php";
return Meteor.http.call("POST", auth_url, {
data: {
'apiNo':'1',
'user':'test',
'pass':'test123',
'message':'hi',
'number':'+905075587***',
'from':'test',
},
headers: {
"content-type":"application/json",
"Accept":"application/json"
},
})
}
});
}
Template.footerLayout.events({
'click #ebultenkaydet': function(e, template) {
Meteor.call("authCall", function(error, results) {
console.log(results); //results.data should be a JSON object
});
});
关于javascript - 如何使用 Meteor.http.call,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31401952/