0

I have a software (Tally) running in my local machine. This software can run as a server (http://localhost, port number 9000). API call can be made using this URL to import and export data. Can I make a http request to this localserver from my application running in a remote webserver.

I tried to do it like this from the webserver:

var request = require('request');
var options = {
    uri: 'http://192.168.0.3:9000',
    method: 'GET'
};
request(options, function (error, response, body) {
    if (error) {
        console.log("Invalid Network Details");
    } else {
        if (response.statusCode == 200) {
            console.log(body);
        } else {
            console.log("Unauthorized Access!!");
        }
    }
});

I am getting an output "Invalid network Details"

Shiju S S
  • 51
  • 1
  • 9
  • *Invalid network Details* is a hardcoded string that you've written code to output if there is any value in `error`. How about actually looking at `error` to see what it says? – Quentin Nov 06 '17 at 08:38
  • "Can I make a http request to this localserver from my application running in a remote webserver" — How remote? Is it on the same LAN? – Quentin Nov 06 '17 at 08:39
  • Application is running in the webserver. I want to import some data to the server from my local computer using exposed api calls – Shiju S S Nov 06 '17 at 09:36
  • Are the webserver and local computer on the same LAN? How remote is "remote"? – Quentin Nov 06 '17 at 09:38
  • Not in the same LAN. Software is running in my desktop. It exposes some API. I want to call it from my web application – Shiju S S Nov 06 '17 at 11:00

2 Answers2

0

I don't know about tally application, BUT in my opinion, you should open the 9000 port in the firewall (and in your router if your webserver is in a different network). In your application, instead of using http://localhost in the remote webserver you have to use the the ip of your local machine (if you are in the same network) or the public address of your local machine (if your computer and your webserver are on diferent networks).

PD. your public address usually changes every x time (could be a dayor could be a month) so I would use noip o something like.

jesus_m90
  • 26
  • 5
  • I have edited the code using ipaddress. Can you check code? – Shiju S S Nov 06 '17 at 08:35
  • is your webserver on the same network that your local machine? if not the ip address `192.168.0.3` you should use is the one that your isp assigns to you local machine's network (you can see it here http://whatismyipaddress.com/es/mi-ip) don't forget openning the port in the router and in the firewall as I said before. – jesus_m90 Nov 06 '17 at 09:34
0

You said

Not in the same LAN

and

http://192.168.0.3:9000

That IP address is in a private IPv4 address space. It can't be accessed (directly) over the Internet.

You need to give the server a public facing IP address (possibly by configuring port forwarding on your router) and then direct your requests to that address.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335