setTimeout does not take effect
1n7erface opened this issue · comments
借口 commented
client := resty.New()
client.SetTimeout(3 * time.Second)
client.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
resp, _ := client.R().
EnableTrace().
SetHeader("Cookie", "rememberMe=agent").
SetHeader("User-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36").
SetHeader("Accept", "*/*").
SetHeader("Accept-Language", "zh-CN,zh;q=0.9").
SetHeader("Connection", "close").
Get("http://43.136.81.55:9001")
fmt.Println(resp.Request.TraceInfo())
When I use this code to request, the timeout here does not take effect because the protocol of the website is websocket.
When I used net/http to access, I found that the reason why the timeout did not take effect was when reading the response packet.
I think the ideal result should be to return status code and response headers and an empty response body.
Looking forward for your reply, thank you.
gospider commented
package main
import (
"log"
"github.com/gospider007/requests"
)
func main() {
resp, err := requests.Get(nil, "http://43.136.81.55:9001/")
if err != nil {
log.Panic(err)
}
log.Print(resp.StatusCode())
}