2
如何集成node.js和java微服务。我可以从java spring mvc调用节点休息api,但无法将数据发布到节点api。在节点项目中获取请求对象中的空主体。从Java Spring MVC调用Node.Js Rest API(POST)
FYI:Node.js的(表达)-REST API(POST方法) Spring MVC的-REST -API(POST方法)
的Java:
String url = "localhost:3010/upload";
JSONObject jsonob1=new JSONObject(); jsonob1.put("upfile", file);
jsonob1.put("ty", "ACT");
HashMap<String, String> header = getHeaderValues(uploadreq.getAuthToken(), "action");
status = getHttpClient.executePostRequest(url,jsonob1,header);
LOGGER.debug("result {}", status);
的NodeJS:
var express = require("express");
var router = express.Router();
router.post('/upload', function (req, res) { console.log(req); });
请发布您的代码正在工作,您的代码不是。 –
String url =“http:// localhost:3010/upload”; JSONObject jsonob1 = new JSONObject(); jsonob1.put(“upfile”,file); \t jsonob1.put(“ty”,“ACT”); \t HashMap header = getHeaderValues(uploadreq.getAuthToken(),“action”); \t status = getHttpClient.executePostRequest(url,jsonob1,header); \t LOGGER.debug(“result {}”,status); –
NodeJs- var express = require(“express”); var router = express.Router(); router.post('/ upload',function(req,res){ \t console.log(req); }); –