req icon indicating copy to clipboard operation
req copied to clipboard

Socks4 Proxy Support

Open APT-ZERO opened this issue 1 month ago • 3 comments

Hello Please add support for Socks4 proxy Thanks

APT-ZERO avatar Nov 18 '25 11:11 APT-ZERO

You can use something like https://github.com/SteffenLoges/socks4

Then use the SetDial function of your req client to make it use the SOCKS4 dialer

oddmario avatar Nov 29 '25 15:11 oddmario

could you please give me a sample? @oddmario Is it possible to use https://github.com/wzshiming/socks4 ? he also has a socks5 lib + udp support https://github.com/wzshiming/socks5 it maybe able to fix https://github.com/imroc/req/issues/347

APT-ZERO avatar Nov 30 '25 19:11 APT-ZERO

could you please give me a sample? @oddmario Is it possible to use https://github.com/wzshiming/socks4 ? he also has a socks5 lib + udp support https://github.com/wzshiming/socks5 it maybe able to fix #347

This is an example using https://github.com/SteffenLoges/socks4:

package main

import (
	"context"
	"fmt"
	"net"
	"time"

	"github.com/SteffenLoges/socks4"
	"github.com/imroc/req/v3"
)

func main() {
	client := req.C()

	protocol := socks4.SOCKS4     // socks4.SOCKS4 or socks4.SOCKS4A
	proxyAddr := "127.0.0.1:1080" // proxy address with port
	userID := ""                  // userID string for authentication, leave blank if no authentication is required
	timeout := time.Second * 5    // use 0 to dial without a timeout

	socks4Dialer := socks4.Dialer(protocol, proxyAddr, userID, timeout)

	client.SetDial(func(ctx context.Context, network string, addr string) (net.Conn, error) {
		return socks4Dialer(network, addr)
	})

	req_ := client.R()

	resp, err := req_.Send("GET", "https://google.com/humans.txt")
	if err != nil {
		fmt.Println(err)

		return
	}

	fmt.Println(resp.String())
}

If https://github.com/wzshiming/socks4 returns a Dialer similarly, you can use it like the above code

oddmario avatar Nov 30 '25 20:11 oddmario