节点ACS 404未找到Java http客户端的响应代码

Node ACS 404 Not found response code to Java http client

本文关键字:客户端 http 响应 代码 Java ACS 节点      更新时间:2023-09-26

我正在做一个项目,其中有一个Java调度器,它是一个HTTP客户端,并将xml作为数据发送到我的节点应用程序。在application.js的索引函数中,我已经编写了接收xml并将相应的xml转换为json的逻辑,但当我运行应用程序时,我会从acs获得404响应代码,但在从浏览器发送请求时也是如此。请告诉我这方面我缺少什么。我发布了javahttp客户端和node-acs代码。

Java HTTP客户端代码是

URL URL=新URL("http://localhost:port/");HttpURLConnection httpCon=(HttpURLConnection)url.openConnection();httpCon.setDoOutput(true);httpCon.setRequestMethod("POST");DataOutputStream os=新数据输出流(httpCon.getOutputStream());PrintWriter pw=新的PrintWriter(os);pw.println(xmlString.toString());pw.flush();System.out.println(httpCon.getResponseCode());System.out.println(httpCon.getResponseMessage());

以下是我的ACS索引函数:

函数索引(req,res){console.log("TEST*************************");req.on("数据",函数(数据){console.log("数据到达");});req.on('end',function(){console.log('POSTed:');res.writeHead(200);res.end();});}

我将代码运行为:acs run --port 7654

从上面的代码中,我在我的javahttp客户端中得到了404响应代码,但如果我在一个简单的js文件中写下相同的节点逻辑,则为:

http.createServer(函数(req,res){req.on("数据",函数(数据){console.log("数据到达");});req.on('end',function(){console.log('Done');res.writeHead(200);res.end();});}).侦听('7654',function(){console.log("服务器连接到:"+7654);});

并运行与node <jsfilename>相同的程序,则工作正常,并向javahttp客户端发送200OK响应。

1-我在Node ACS应用程序中遗漏了什么吗?

2-我们是否需要在node acs应用程序中配置http服务器,因为如果我在application.js文件中编写以下逻辑,那么它也可以在node cs中工作:

http.createServer(函数(req,res){req.on("数据",函数(数据){console.log("数据到达");});req.on('end',function(){console.log('Done');res.writeHead(200);res.end();});}).侦听('7654',function(){console.log("服务器连接到:"+7654);});

我找到了解决方案。Java调度程序HTTP请求是POST请求,在NodeACS应用程序中,对于索引方法,我没有提到方法属性。现在我提到了"方法":"POST",然后它可以正常工作。