1. So getting an odd error:

    Code:
    ConnectFailure (The requested address is not valid in its context.
    )
    If I replace localhost with say google.com, it works fine. But if I use http://localhost/blah or http://127.0.0.1/blah I get this error. Trying to make calls to a local API I am developing. Any hints?

    Thanks in advance!
     
  2. Maybe try using you local rooter adress or your real ip while you are trying to connect.
    Also pasting your code could help to find a solution.
     
  3. This isn't a server on the internet. It's local and for testing. I can connect to the server just fine using "client.connect localhost:28015" from the console.

    Sure, here you go.

    Code:
    webrequest.Enqueue("http://localhost:9090/", null, (code, response) =>
                    {
                        Puts($"{code} {response}");                }, this, RequestMethod.GET, null, 100f);
    Using "http://google.com:9090/" "works" in that it gives a failure to connect, rather than a failure to resolve, with the following:
    Code:
    ConnectFailure (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
    )
    Using "http://google.com/" works and returns the body.
    Using "http://127.0.0.1/" fails with the "context" error above.

    I can use the local hostname (machine name), but that's a work-around that I don't know if it will work on my Linux servers. Tried adding an entry into System32/etc/hosts that points to 127.0.0.1 and that fails.

    All the localhost/127.0.0.1/127.0.1.1/etc work perfectly fine in web browsers / curl.

    It really seems like webrequest.Enqueue has a problem with anything that resolves to the local loopback address.
    [DOUBLEPOST=1532427161][/DOUBLEPOST]Just to verify, also tried with my local IP (192.168.x.x) and that worked.
     
    Last edited by a moderator: Jul 24, 2018
  4. Try to up web server on standart port (80) and add line to hosts file like 127.0.0.1 localhost, reboot your system and try. This code must works:
    Code:
    webrequest.Enqueue("http://localhost/", null, (code, response) =>
    Hosts file will imit DNS server.

    Also try with differend names in hosts file, for example: 127.0.0.1 test.loc test.com ...
     
  5. Calytic

    Calytic Community Admin Community Mod

    OxideMod/Oxide.Core

    As you can in the link above, the WebRequests library in Oxide simply uses the underlying HttpWebRequest class provided as part of .NET in System.Net. Whether or not a particular endpoint is valid has to do with the native networking of your OS and the ability (or lack thereof) of .NET to integrate with said networking. It has very little to do with Oxide itself and as such there isn't much, if anything, we can do about it, sorry.
     
  6. Aah I suspect the problem is here: OxideMod/Oxide.Core

    It's binding the client to an IP, which cannot get to localhost. Perhaps making an option Enqueue that doesn't do this would be useful for anyone working on anything that isn't a public facing IP or on the same network as the IP the server is bound to?

    I understand the usefulness of this, allowing you to specify the IP the client is coming from more multi-tenant systems. But it would be nice to be able to override it to avoid this behavior, if it would allow connecting to localhost. Again, this is just what I suspect.

    Just for reference, i am running on Windows 10. I have tried setting the server IP to 127.0.0.1, my local LAN IP, and 0.0.0.0
     
  7. Wulf

    Wulf Community Admin

    That binds to your server's local IP if behind a router or external IP if assigned directly on that machine's network adapter. Shouldn't be any reason why "localhost" would not be accessible. The "endpoint" is the machine sending the request. Ex. If behind a router, IP could be something like 192.168.1.101; whereas if your machine is directly connected to the internet, it could be 201.29.13.28. Either way, should still work and an option would not make sense for this. If it is indeed an issue caused by this, then a fix would need to be made to handle it, not an option.

    This functionality is key for preventing any servers with multiple network adapters from using the primary adapter only instead of their intended/assigned IP address. Also keep in mind that IP binding still happens regardless of us assigning an IP or not, it just goes for whatever is the primary IP address on that machine.
     
  8. Understood. I'm not running anything exotic here. It's Windows 10 pro. Can't make web requests to localhost. I'm explaining everything I have tried.

    There's either something I am not getting or there is a bug connecting. If I had the time, I would totally try to figure out compiling Oxide / Oxide Rust and giving it a shot with that portion commented out, but I don't have the time to do that at the moment.

    It seems pretty easy to test. Make any webrequest to localhost/127.0.0.1. Even if it's not able to connect you should see something like a connection failure instead of the "context" failure. And if it's not showing up anywhere else, then it's something on my end.

    Just for complete clarity so the entire problem is in one post:

    With the following code:
    Code:
    webrequest.Enqueue("http://localhost:9090/", null, (code, response) =>
                    {
                        Puts($"{code} {response}");                }, this, RequestMethod.GET, null, 100f);
    This is what an expected failure to connect looks like (like if you substitute google.com for localhost):
    Code:
    ConnectFailure (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
    )
    And this is what it looks like when trying to do localhost/127.0.0.1/a hosts entry pointing to 127.0.0.1:
    Code:
    ConnectFailure (The requested address is not valid in its context.
    )
     
  9. Wulf

    Wulf Community Admin

    Here's a build if you'd like to test:
     
  10. Thanks so much. Looks like this is working:

    Code:
    [PoundbotConnector] 0 Error: ConnectFailure (No connection could be made because the target machine actively refused it.
    )
    No connection could be made because the target machine actively refused it.
    In the middle of breaking my API, but that's the correct error I expect when it's not running. :) Or at least more correct.
     
  11. Wulf

    Wulf Community Admin

    Here's another with a check for loopback:
     
  12. Looks like that's working fine.
     
  13. Wulf

    Wulf Community Admin

    Great! Thanks for testing and the report. :)
     
  14. Thanks for the fix! Really appreciate it!