NodeJS发送 - PubSub (Websocket)
本节内容为NodeJS实现GoEasy Rest接口发送消息, 使用时,可参阅Rest接口的详细介绍
NodeJS
const http = require("https");
const options = {
hostname: "rest-hz.goeasy.io", //新加坡rest-host:rest-singapore.goeasy.io
path: "/v2/pubsub/publish",
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
};
const data = {
appkey: "您的appkey",
channel: "test_channel",
content: "Hello, GoEasy!",
};
let result = "";
const req = http.request(options, (res) => {
console.log(res.statusCode);
res.setEncoding("utf8");
res.on("data", (chunk) => {
result += chunk;
});
res.on("end", () => {
console.log(result);
});
});
req.on("error", (e) => {
console.error(e);
});
req.write(JSON.stringify(data));
req.end();
REST Host
杭州: rest-hz.goeasy.io
新加坡: rest-singapore.goeasy.io