SOCKS Proxy vs HTTP Proxy: Khi Nào Dùng Gì?
Có nhiều loại proxy khác nhau. Bài viết so sánh SOCKS vs HTTP proxy và khi nào dùng loại nào.
HTTP Proxy
- Chỉ hoạt động với HTTP/HTTPS traffic
- Có thể modify headers, cache
- Hiểu HTTP protocol
- Phổ biến nhất cho web scraping
SOCKS Proxy
- Protocol-agnostic (bất kỳ TCP/UDP)
- Không modify traffic
- Lower level, more versatile
- SOCKS4 (TCP only) vs SOCKS5 (TCP + UDP + auth)
So Sánh
| Feature | HTTP Proxy | SOCKS5 Proxy |
|---|---|---|
| Protocols | HTTP/HTTPS | Any TCP/UDP |
| Speed | Có thể cache | Không cache |
| Authentication | Basic/Digest | Username/Password |
| Use cases | Web browsing | Gaming, torrents, FTP |
| Web scraping | ✅ Tốt | ✅ Tốt |
Python + HTTP Proxy
import requests
proxies = {
'http': 'http://user:pass@proxy.vinaproxy.com:8080',
'https': 'http://user:pass@proxy.vinaproxy.com:8080'
}
response = requests.get('https://example.com', proxies=proxies)
Python + SOCKS5 Proxy
# Cần cài: pip install requests[socks]
import requests
proxies = {
'http': 'socks5://user:pass@proxy.vinaproxy.com:1080',
'https': 'socks5://user:pass@proxy.vinaproxy.com:1080'
}
response = requests.get('https://example.com', proxies=proxies)
Selenium + SOCKS Proxy
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
opts = Options()
opts.add_argument('--proxy-server=socks5://proxy.vinaproxy.com:1080')
driver = webdriver.Chrome(options=opts)
driver.get('https://example.com')
Playwright + Proxy
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(proxy={
"server": "socks5://proxy.vinaproxy.com:1080",
"username": "user",
"password": "pass"
})
page = browser.new_page()
page.goto('https://example.com')
Khi Nào Dùng SOCKS?
- Cần UDP support
- Non-HTTP protocols (FTP, SMTP)
- Bypass strict firewalls
- Khi HTTP proxy bị detect
Khi Nào Dùng HTTP?
- Web scraping thông thường
- Cần header modification
- Caching benefits
- Đơn giản hơn để setup
VinaProxy – Hỗ Trợ Cả Hai
- HTTP/HTTPS proxy
- SOCKS5 proxy
- Residential IPs
- Giá chỉ $0.5/GB
