imroc / req

Simple Go HTTP client with Black Magic
https://req.cool
MIT License
4.12k stars 334 forks source link

How do I set a timeout for a get or post request? For example, if no data is returned within 3 seconds, it is considered a failure #343

Closed 2622594863 closed 2 months ago

2622594863 commented 2 months ago

How do I set a timeout for a get or post request? For example, if no data is returned within 3 seconds, it is considered a failure. Here's my code

rsp, err := client.R().Post(url + "/Login/Get")

2622594863 commented 2 months ago

Thank you. I found it. Thanks for your trouble client := req.C() client.SetTimeout(5 * time.Second)