我试图通过Twilio API发送短信,但是当我通过jQuery在我的应用程序使用它发送短信的投掷通过TWILIO API
https://api.twilio.com/2010-04-01/Accounts/SID/Messages.json 401 (UNAUTHORIZED)
但是,当我使用通过相同的SID和身份验证令牌其网站我能够发送短信。
请帮助如何使这项工作。
我的代码:
$(document).ready(function() {
$("#btnSubmit").click(function(){
$.ajax({
type: 'POST',
username: 'SID',
password: 'KEY',
url: 'https://api.twilio.com/2010-04-01/Accounts/SID/Messages.json',
xhrFields: {
withCredentials: true
},
data: {
"To" : "+918967385884",
"From" : "+12016902194",
"Body" : "Hello World"
},
success: function(data) {
console.log(data);
},
error: function(data) {
console.log(data);
}
});
});
});
但后来我是怎么能够从twilio网站直接发送短信,也可以我使用Spring作为我的服务器端。有没有什么代码可以帮我解决这个问题 –