[英]Calling a file from local machine as a web service Javascript
I am working on a project. 我正在做一个项目。 Where i need to call a web service which returns a SOAP message. 我需要调用返回SOAP消息的Web服务的地方。 Now the problem is that the webservice is hosted on an IntraNet and i can not access it. 现在的问题是,Web服务托管在IntraNet上,我无法访问它。 I have been provided with a txt file that contains a sample response of the web service. 已为我提供了一个txt文件,其中包含Web服务的示例响应。 I have to manipulate the reply in my code Is there anyway I can call this txt file instead of the web service and get the response and manipulate it ? 我必须操纵代码中的回复?无论如何,我可以调用此txt文件而不是Web服务来获取响应并进行操作吗?
You can do that using node and Express JS. 您可以使用node和Express JS来实现。 Install Node from www.nodejs.com 从www.nodejs.com安装Node
after installing and running node, go to your directory and install express : 安装并运行节点后,转到目录并安装express:
npm install express npm安装快递
then create a file called app.js and run it with node : node app.js 然后创建一个名为app.js的文件,并使用node运行它:node app.js
var express = require('express')
, app = module.exports = express();
app.get('/', function(req, res){
res.send('<p>Static File Server for files</p>');
});
app.get('/txt/:file(*)', function(req, res, next){
var file = req.params.file
, path = __dirname + '/public/txt/' + file;
res.sendFile(path);
});
if (404 == err.status) {
res.statusCode = 404;
res.send('File Does Not Exist!');
} else {
next(err);
}
});
if (!module.parent) {
app.listen(8023);
console.log('Express started on port 8023');
}
put the folder that has your txt file in /public/txt/ so public and the app.js are in the same directory. 将拥有txt文件的文件夹放在/ public / txt /中,以便public和app.js位于同一目录中。 you should run the app.js with node after this is done. 完成此操作后,应使用node运行app.js。 go to your web browser : navigate to localhost:8023/txt/yourfile.txt and if everything is working find you should be able to get the file. 转到网络浏览器:导航至localhost:8023 / txt / yourfile.txt,如果一切正常,则应该可以获取该文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.