Dev.to WebDev 🛠 Dev 👁 0 📖 6 min read

HTTP Proxy vs SOCKS5: Which Gateway String to Use

An HTTP proxy and a SOCKS5 proxy are two ways to hand a request to the same gateway. The HTTP form understands web requests, so it can open a tunnel for an HTTPS page and it can also see a plain HTTP page. SOCKS5 carries

HTTP Proxy vs SOCKS5: Which Gateway String to Use

 An HTTP proxy and a SOCKS5 proxy are two ways to hand a request to the same gateway. The HTTP form understands web requests, so it can open a tunnel for an HTTPS page and it can also see a plain HTTP page. SOCKS5 carries the connection without reading it as a web request, and it can ask the gateway to look up the hostname. A script that picks the wrong scheme either leaks its own address or asks the gateway a question that gateway does not answer.

What an HTTP proxy forwards

An HTTP proxy is a relay that speaks HTTP. Your client sends it a web request, and the site records the relay address instead of yours. A plain http:// target can travel as a normal proxied request, which means the proxy can read that payload. An https:// target usually goes through HTTP CONNECT. The proxy opens a TCP tunnel to the host and port, then your TLS handshake runs inside that tunnel. The proxy sees the destination host, not the page body.

That split is why a store on HTTPS and a health check on HTTP can behave differently on the same gateway string. CONNECT is enough for the store. The health check is a request the proxy can parse. A longer walk through the relay itself is in what an HTTP proxy actually forwards.

What SOCKS5 changes

A SOCKS5 proxy is a general relay. It accepts a connect command, opens a TCP connection, and shuttles bytes. It does not parse the request as HTTP, so the same gateway string can carry a browser, a mail client, or a script that is not speaking the web.

The part that changes a scrape is where the hostname is resolved. A URL that starts with socks5:// often resolves the name on your machine, then sends the gateway an IP address. A URL that starts with socks5h:// sends the hostname and asks the gateway to resolve it. The lookup then sits next to the exit IP the site will see. A local lookup can still leave a DNS query on your office resolver, even when the page itself left through the gateway.

socks5h://USER:PASS@HOST:PORT

socks5h is the form to copy when the dashboard offers SOCKS5 and the job is a website. The trailing h is the whole difference between a name resolved at your desk and a name resolved at the exit.

Which string matches the client

The client library decides the scheme, not the target site. requests, httpx, and a browser extension all want a URL. An HTTP gateway uses a URL that starts with http://. A SOCKS gateway uses socks5h:// once PySocks, or the equivalent extra, is installed. The dashboard prints one of those two forms. That printed form is the one that belongs in the client.

HTTP proxy SOCKS5 (socks5h)
What the gateway parses Web requests, plus CONNECT for HTTPS A connect command and the bytes
Where the name is looked up Usually at the gateway for CONNECT At the gateway, because of the h
A client it fits Browsers, curl, HTTP libraries The same HTTP clients, plus apps that are not HTTP
What you copy The http:// string from the dashboard The socks5h:// string from the dashboard

A long product crawl can use either row. The row that fails is the one you invent. socks5:// on a gateway that was given an HTTP port returns a handshake error. http:// pointed at a SOCKS port does the same. The port in the dashboard and the scheme in the string have to be the pair that page printed.

Check the exit before the real host

The exit check is one request to an echo service, through the gateway, before any catalog URL. The printed address is the IP the next site will see. If that address is your office IP, the scheme or the missing dict key sent the call around the gateway, and the real host would have seen you too.

import os
from urllib.parse import quote
import requests

user = quote(os.environ["PROXY_USER"], safe="")
password = quote(os.environ["PROXY_PASS"], safe="")
host = os.environ["PROXY_HOST"]  # host:port from the dashboard
proxy = f"socks5h://{user}:{password}@{host}"

session = requests.Session()
session.trust_env = False
session.proxies = {"http": proxy, "https": proxy}

print(session.get("https://api.ipify.org", timeout=30).text)

quote keeps a password that contains @ or : inside the userinfo. A raw @ splits the URL, and the gateway answers as if the login were wrong. trust_env = False stops a leftover HTTPS_PROXY in the shell from replacing the string you just set. Both dict keys carry the same string, because requests picks the key from the target URL. A missing https key sends the echo service out from your own address.

You point the same session at the real host only after the printed address matches the country on the proxy user. The gigabytes start on that second request.

Where the country and the session live

The country and the session mode usually live in the username, not in the scheme. A rotating user gives the next request a new exit IP from the pool. A sticky user holds one exit IP for one job, then lets it go. HTTP and SOCKS5 can both carry that username. Changing http:// to socks5h:// does not change the country, and it does not pin the IP.

A price list can use the rotating user. Each page leaves from another household, and one connection does not absorb the whole list. A checkout uses the sticky user, so the item page and the payment page share a visitor. IPOasis sticky sessions on dynamic residential hold that address for up to 120 minutes. When the window ends, the next request can leave from a different household IP. The dashboard builds the username. That string goes in PROXY_USER.

Where the gateway string comes from

The host, the port, the username, and the password come from the provider dashboard, already paired as an HTTP string or a SOCKS5 string. IPOasis lists dynamic residential proxies from $0.78 per GB, with HTTP and SOCKS5 on the same balance. Unused gigabytes stay on the balance, so the exit check does not burn a monthly plan. You copy the pair the dashboard printed, run the echo once, and only then open the host you actually need.

FAQ

What is the difference between an HTTP proxy and SOCKS5?

An HTTP proxy speaks web requests and opens a CONNECT tunnel for HTTPS. SOCKS5 carries the TCP connection without parsing it as HTTP, so the same gateway can serve clients that are not browsers. For a scrape, the practical difference is the URL scheme and where the hostname is resolved.

What does socks5h mean?

socks5h means the proxy resolves the hostname. The client sends the name, and the lookup happens at the gateway, next to the exit IP. Plain socks5 often resolves the name on your machine first, which can leave a DNS query on your own resolver.

Can one username work on both?

One username can ride on either scheme when the provider serves HTTP and SOCKS5 from the same account. The host and port still have to match the scheme. The dashboard shows that pair. The country and the sticky or rotating mode stay in the username either way.

Why did the echo service print my office IP?

The call missed the gateway. A missing https key, an HTTPS_PROXY value still set in the shell, or a scheme that does not match the port will all send that request from your own address. The printed IP is the check. The catalog request waits until that IP is the exit you picked.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.