github.com/gospider007/requests@v0.0.0-20240506025355-c73d46169a23/test/request/localAddr_test.go (about)

     1  package main
     2  
     3  import (
     4  	"net"
     5  	"testing"
     6  
     7  	"github.com/gospider007/requests"
     8  )
     9  
    10  func TestLocalAddr(t *testing.T) {
    11  	resp, err := requests.Get(nil, "https://httpbin.org/anything", requests.RequestOption{
    12  		LocalAddr: &net.TCPAddr{ //set dns server
    13  			IP: net.ParseIP("192.168.1.239"),
    14  		},
    15  	})
    16  	if err != nil {
    17  		t.Fatal(err)
    18  	}
    19  	if resp.StatusCode() != 200 {
    20  		t.Fatal("http status code is not 200")
    21  	}
    22  }