
Teach you to hang a proxy with axios.
Brothers engaged in network development should have encountered this situation: local debugging interface is always restricted by the target site, or need to operate in bulk when the ip is pulled black. This time to find a reliable proxy ip service provider is particularly critical, such as we want to focus on today'sipipgoThey specialize in high quality proxy ip, and those who have used them say they are stable.
Why do I need to hang a proxy ip?
For example, if you write a crawler script to grab data with axios and suddenly get banned after sending dozens of requests in a row, you can perfectly solve the problem if you have a proxy ip pool and change the "armor" for each request. ipipgo's ip pool covers 200+ regions and supports per-minute billing, which is especially suitable for this kind of scenario where you need to switch frequently. This is especially suitable for this kind of scenario, which requires frequent switching.
// Basic axios example
const axios = require('axios');
const instance = axios.create({
httpsAgent: new (require('https-proxy-agent'))('http://user:pass@proxy.ipipgo.cc:8888')
})
Three key points for matching agents
1. The agreement has to be right.: https request must be equipped with https proxy, don't be silly to use http proxy to deal with https request
2. Don't misspell the authentication information: A lot of newbies planted here, username and password contain special symbols remember to encodeURIComponent escape
3. Timeout settings should be reasonableIt is recommended to set a timeout of 3-5 seconds to switch the proxy ip in time when it encounters a lag.
| parameters | example value |
|---|---|
| Agent Address | proxy.ipipgo.cc |
| ports | 8888/8899 |
| Authentication Methods | Basic Auth |
Real-world configuration steps
Here's an example demonstration in a node.js environment (note the replacement of your_username and your_password with the real credentials you get in the ipipgo backend):
const https = require('https');
const HttpsProxyAgent = require('https-proxy-agent');
const proxyConfig = {
host: 'proxy.ipipgo.cc',
auth: 'Your account:Your password' // Be careful not to reverse the colons.
};
async function fetchData() {
const agent = new HttpsProxyAgent(proxyConfig);
const response = await axios.get('https://目标网站.com/api', {
httpsAgent: agent,
timeout: 5000
});
console.log(response.data);
}
A guide to stepping through the pits (QA session)
Q: What should I do if my proxy ip suddenly fails?
A: This situation is recommended to use ipipgo's automatic switching function, their api can get the list of available ip in real time, write a rotation logic will be able to deal with it
Q: Requests slowing down significantly?
A: Check whether the socks proxy, https proxy to choose a specially optimized channel. ipipgo's exclusive acceleration line latency can be pressed to 200ms or less!
Q: How can I tell if a proxy is in effect?
A: You can use this check interface: https://api.ipipgo.cc/checkip, the return ip is not the local ip means it is successful
How to choose a proxy service provider
The agency services on the market are a mixed bag, and here we have to be amenable to themipipgoThe three killer apps:
1. Exclusive ip pool without crash
2. Supporting pay-per-use without waste
3. 7 x 24 hour technical response
Recently, they also have a free 3-day trial for new users, fill in the invitation code when you sign up!AXIOS666You can also get an extra 5G traffic pack.
caveat
A few final rants:
1. production environment remember to put the account password in the environment variable, do not stupidly write in the code
2. add try-catch for important operations, ECONNRESET error will be thrown when the agent is unstable.
3. regularly updated sdk version, last year there is an old version of the https-proxy-agent memory leakage problems
According to the above steps with down, can basically solve the 90% proxy configuration problems. If you still can't figure out the situation, you can go directly to ipipgo official website to find online customer service, their technicians are particularly familiar with the axios adaptation problems, the response speed is much faster than ordinary work orders.

