将Http请求发送到正文中带有Unicode字符的Infobip SMS APi时出现问题。我尝试使用axios
和request
模块,但两者均不适用于unicode值,但适用于普通英语字符。这是代码
var express = require('express');
var request = require('request');
var app = express();
var url = 'http://api.infobip.com/sms/2/text/single'
var options = {
method: 'post',
data: {
'from': 'ME',
'to': '(555) 555-1234',
'text': 'ওহে বিশ্ব',
},
headers: {
'authorization': 'Basic AUTH_KEY',
'content-type': 'application/json',
'accept': 'application/json'
},
url: url
}
request(options, function (err, res, body) {
if (err) {
console.log('Error', err);
}
console.log(res, body);
})
答案 0 :(得分:1)
您可以通过axios进行检查
var express = require('express');
var app = express();
var axios = require("axios");
const config =
{
headers:
{
'authorization': 'Basic AUTH_ID',
'content-type': 'application/json;charset=UTF-8',
'accept': 'application/json'
}
};
axios.post('http://api.infobip.com/sms/2/text/single',
{
'from': 'ME',
'to': '+8801XXXXXX',
'text': 'ওহে বিশ্ব',
},
config,
)
.then(function(response) {
console.log(response.data)
})
.catch(function(error) {
console.log(error)
})