Node ACS 404 Not found response code to Java http client
I am working on a project in which there is a Java scheduler which is a HTTP Client and send xml as data to my node application. In index function of application.js I have written my logic to receive the xml and convert the respective xml to json but when I run my app then I am getting 404 response code from acs but the same is working when I am sending request from browser. Please suggest me what I am lacking in this. I am posting both java http client and node acs code.
Java HTTP Client Code is
URL url = new URL("http://localhost:port/"); HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); httpCon.setDoOutput(true); httpCon.setRequestMethod("POST"); DataOutputStream os = new DataOutputStream( httpCon.getOutputStream()); PrintWriter pw = new PrintWriter(os); pw.println(xmlString.toString()); pw.flush(); System.out.println(httpCon.getResponseCode()); System.out.println(httpCon.getResponseMessage());
Following is my ACS index function:
function index(req, res) { console.log("TEST *********************************"); req.on('data', function (data) { console.log("Data arrived"); }); req.on('end', function () { console.log('POSTed: '); res.writeHead(200); res.end(); }); }
I am runnig the code as: acs run --port 7654
From above code I am getting 404 response code in my java http client but if I write the same node logic in a simple js file as:
http.createServer(function (req, res) { req.on('data', function (data) { console.log("Data Arrived"); }); req.on('end', function () { console.log('Done'); res.writeHead(200); res.end(); }); }).listen('7654', function(){ console.log("Server Connected to : "+ 7654); });
and run the same as node <jsfilename>
then it is working fine and sending 200 OK response to java http client.
1- Am I missing something in Node ACS app?
2- Do we need to configure http server in node acs app because if I write following logic in my application.js file then its working also in node acs:
http.createServer(function (req, res) { req.on('data', function (data) { console.log("Data Arrived"); }); req.on('end', function () { console.log('Done'); res.writeHead(200); res.end(); }); }).listen('7654', function(){ console.log("Server Connected to : "+ 7654); });
I found the solution. The Java scheduler HTTP request is POST request and in the NodeACS app for index method I haven't mentioned method attribute. Now I mentioned "method":"POST" then its working fine.
链接地址: http://www.djcxy.com/p/52512.html上一篇: 确定回调函数JS的数量