NodeJS发送Websocket消息 - GoEasy PubSub

本节内容为NodeJS实现GoEasy Rest接口发送消息, 使用时,可参阅Rest接口的详细介绍

NodeJS

  var http = require('http');

  var appkey = 'Your appkey';
  var channel = 'my_channel';
  var content = 'Hello, GoEasy!';

  var queryParams = 'appkey='+appkey+'&channel='+channel+'&content='+content;

  var options = {
    hostname: '<REST Host>',
    path: '/publish',
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  };

  var req = http.request(options, (res) => {
    res.setEncoding('utf8');
    res.on('data', (result) => {
      console.log(`响应结果: ${result}`);
    });
  });

  req.on('error', (e) => {
    console.error(e);
  });

  req.write(queryParams);
  req.end();

REST Host

杭州: rest-hangzhou.goeasy.io
新加坡: rest-singapore.goeasy.io

results matching ""

    No results matching ""