0

Connecting to the server through browser is possible and i get http code 200, I have directly copied the url from the browser to the node fetch:

   await fetch(`http://localhost:9000/renderAvatar.3d?pant=http://localhost/assets/2.png&face=http://localhost/assets/0.png&shirt=http://localhost/assets/1.png&name=de&trick=e`)   

The other server on the 9000 port is written in c# and has code like this:

HttpListener httpServer;
public void SomeFunction() {
    //Some boilerplate for http server definitely not stolen amogus
    httpServer = new HttpListener();
    httpServer.Prefixes.Add("http://localhost:9000/");
    httpServer.Start();
    Task demo = Server();
    demo.GetAwaiter().GetResult();

}
public async Task server() {
    while(true) {
        HttpListenerContext ctx = await httpServer.GetContextAsync();
        HttpListenerRequest req = ctx.Request;
        HttpListenerResponse resp = ctx.Response;
        if(req.HttpMethod == "GET") {
            if(req.Url.AbsolutePath.ToString() == "/renderAvatar.3d") {
                var parameters = HttpUtility.ParseQueryString(req.Url.Query);
                if(parameters.Count > 3) {
                    var pant = parameters[0].ToString();
                    var face = parameters[1].ToString();
                    var shirt = parameters[2].ToString();
                    var name = parameters[3].ToString();
                    // can't share more code due this is propertiary code

any access from the browser works but why node fetch doesn't work, i have very bad solution to this issue using chrome to open up avatar renderer then close the chrome programatically but this uses way too much memory and quite unncesary.

(This is on linux btw, port 9000 shouldn't be protected by firewall and this is a local server)

thrown error:

FetchError: request to http://127.0.0.1:9000/renderAvatar.3d?pant=http://localhost/assets/2.png&face=http://localhost/assets/0.png&shirt=http://localhost/assets/1.png&name=de&trick=e failed, reason: connect ECONNREFUSED 127.0.0.1:9000
    at ClientRequest.<anonymous> (file:///home/ 


(confidental)/backend/node_modules/node-fetch/src/index.js:108:11)
        at ClientRequest.emit (node:events:527:28)
        at Socket.socketErrorListener (node:_http_client:454:9)
        at Socket.emit (node:events:527:28)
        at emitErrorNT (node:internal/streams/destroy:157:8)
        at emitErrorCloseNT (node:internal/streams/destroy:122:3)
        at processTicksAndRejections (node:internal/process/task_queues:83:21) {
      type: 'system',
      errno: 'ECONNREFUSED',
      code: 'ECONNREFUSED',
      erroredSysCall: 'connect'
    }
drk1
  • 65
  • 11

1 Answers1

1

Turns out changing localhost to 127.0.0.1 on the c# app solves the issue, on linux localhost is automatically converted to 127.0.0.1 but c# app doesn't do that for some odd reason.

httpServer.Prefixes.Add("http://localhost:9000/");

to

httpServer.Prefixes.Add("http://127.0.0.1:9000/");
drk1
  • 65
  • 11