Comments (3)
我目前正在做这样的 smth,我认为这不是更改代理的最佳方式。这是如何做到的?
package main import ( "crypto/tls" "fmt" "time" "github.com/go-resty/resty/v2" ) var gproxy string = "http://127.0.0.1:8081" func main() { c := resty.New(). SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}). SetRedirectPolicy(resty.FlexibleRedirectPolicy(4)) // change proxy in a single go routine go func() { for { time.Sleep(2 * time.Second) gproxy = "http://127.0.0.1:8080" } }() for { time.Sleep(1 * time.Second) r, _ := c. SetProxy(gproxy). R().Get("https://google.com/") fmt.Println(r.StatusCode()) } }
this can help you
package main
import (
"log"
"github.com/gospider007/requests"
)
func main() {
resp, err := requests.Get(nil, "https://httpbin.org/anything", requests.RequestOption{
Proxy: "", //set proxy,ex:"http://127.0.0.1:8080","https://127.0.0.1:8080","socks5://127.0.0.1:8080"
})
if err != nil {
log.Panic(err)
}
if resp.StatusCode() != 200 {
log.Panic("status code is not 200")
}
}
from resty.
我目前正在做这样的 smth,我认为这不是更改代理的最佳方式。这是如何做到的?
package main import ( "crypto/tls" "fmt" "time" "github.com/go-resty/resty/v2" ) var gproxy string = "http://127.0.0.1:8081" func main() { c := resty.New(). SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}). SetRedirectPolicy(resty.FlexibleRedirectPolicy(4)) // change proxy in a single go routine go func() { for { time.Sleep(2 * time.Second) gproxy = "http://127.0.0.1:8080" } }() for { time.Sleep(1 * time.Second) r, _ := c. SetProxy(gproxy). R().Get("https://google.com/") fmt.Println(r.StatusCode()) } }this can help you
package main import ( "log" "github.com/gospider007/requests" ) func main() { resp, err := requests.Get(nil, "https://httpbin.org/anything", requests.RequestOption{ Proxy: "", //set proxy,ex:"http://127.0.0.1:8080","https://127.0.0.1:8080","socks5://127.0.0.1:8080" }) if err != nil { log.Panic(err) } if resp.StatusCode() != 200 { log.Panic("status code is not 200") } }
Hello @gospider007 - I'm glad to see a new open-source developer on GitHub. Welcome to the Open source community!
However, promoting your new library in another open-source library repository seems inappropriate.
https://github.com/search?q=repo%3Ago-resty%2Fresty+gospider007&type=issues
from resty.
@rew1nter Thanks for reaching out; I'm sorry for the delay.
You could change the Proxy URL anytime by using client.SetProxy
method. However, currently, Resty does not provide a lock for client properties. I recommend you use RWMutex at your end.
Note: Resty v3 comes with a lock and many new features.
from resty.
Related Issues (20)
- CVE-2023-45286 HOT 3
- Breaks application from Ctrl-C handling HOT 1
- Brotli support HOT 1
- How to handle response if a call to API returns 200 with struct A, or 201 with struct B? HOT 3
- SetResult failed with httpmock HOT 2
- CVE-2023-45286: HTTP request body disclosure HOT 3
- SetProxy HOT 3
- The request with SetFileReader retry time great than 1 will has issues HOT 1
- Signing requests with path parameters HOT 1
- Clone or copy of existing client HOT 6
- cache middleware HOT 5
- retrying of non-idempotent methods HOT 2
- Path param encoding is broken
- can't use image.decode on rawbody HOT 1
- Can it support socket5 proxy? HOT 2
- Resty retry function does not work in Slack as custom http client HOT 2
- Middleware around resty.Request.Execute including retries HOT 1
- about proxy
- Client: Improve its creation flow and its options
- Request: Improve Request struct and its usage
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from resty.