发送JSON到地址不同然后res

问题描述 投票:0回答:1

我创建了一个小型快递模块。这个atm听url在localhost上运行但是计划收听triggerURL:ListenPort并从外部服务运行。

clientA:服务器应该从网页(triggerURL)接收调用,并作为响应将JSON对象发送到unity_url

clientB:一个团结的应用程序将打开听tazxswpoi。

问题是,虽然将JSON发送到res并返回clientA没有问题,但我不确定如何使用SendingPortresp创建新的可写流并将json发送到clientB。

writable
javascript node.js json stream
1个回答
1
投票

您需要向目标网址发送请求。例如(使用var express = require('express'); var fs = require('fs'); var app = express(); var triggerURL = ''; //i'll send an http request to this adress to trigger the action from server var JSON = { item: "seeds", Answers: "5", richText: "<b>How can you reduce crop toxicity by turning plants upside down?</b><br/>Idea:<br/> Upside-down gardening is a hanging vegetable garden being the suspension of soil and seedlings of a kitchen garden to stop <b>pests</b> and blight,and eliminate the typical gardening tasks of tilling, weeding, and staking plants." } var port = process.env.PORT || 3000; var ListenPort = '8086'; // my port to recieve triggers var SendingPort = '4046'; // which unity will listen to var unity_url ='185.158.123.54:'+SendingPort; //fake IP, just for the example //triggerURL app.get('/', function(req,res){ var resp = JSON.stringify(JSON); var writable = fs.createWriteStream(); //res.json(JSON); //instead i wanna send it to unity_url; }); //app.listen(ListenPort); app.listen(port); )。

node-fetch
© www.soinside.com 2019 - 2024. All rights reserved.