Request hangs with Axios, but succeeds with curl?

Viewed 38
let response = await axios("https://api.my-ip.io/ip", {
  proxy: { host: "127.0.0.1", port: 8118, protocol: "http" },
});

This hangs, although sometimes the promise resolves with response status message "Connection Established".

Running the command: curl -x http://127.0.0.1:8118 https://api.my-ip.io/ip returns the expected result from the server.

Why is the axios request exhibiting this behavior?

1 Answers

I was able to solve this, but it required using this package: https://github.com/delvedor/hpagent

import axios from "axios";
import { HttpProxyAgent, HttpsProxyAgent } from "hpagent";

it("should get a response", async () => {
  const agent = new HttpsProxyAgent({ proxy: "http://127.0.0.1:8118" });
  let response = await axios("https://api.my-ip.io/ip", {
    httpsAgent: agent,
  });
  console.log(response);
});
Related