1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| // 随机生成IP地址方法 func genIpaddr() string { rand.Seed(time.Now().Unix()) ip := fmt.Sprintf("%d.%d.%d.%d", rand.Intn(255), rand.Intn(255), rand.Intn(255), rand.Intn(255)) return ip }
func postUrlResponse(Referer, requestURL, userkey, session string, wg *sync.WaitGroup) (string, string) { defer wg.Done() //logger.Println("[GET]=>" + requestURL) randIp := genIpaddr() proxy := func(_ *http.Request) (*url.URL, error) { return url.Parse(PROXY_ADDR) }
httpTransport := &http.Transport{ //解决x509: certificate signed by unknown authority TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, Proxy: proxy, }
//req, err := http.NewRequest("POST", requestURL, nil) data := url.Values{} data.Set("data", datas) data.Set("__k", userkey) u, _ := url.ParseRequestURI(requestURL) u.RawQuery = data.Encode() urlStr := fmt.Sprintf("%v", u) // "https://api.com/user/?name=foo&surname=bar"
httpClient := &http.Client{ Transport: httpTransport, //解决x509: certificate signed by unknown authority Timeout: time.Second * 10, //超时时间 }
//req, err := http.NewRequest("POST", urlStr, nil) req, err := http.NewRequest(http.MethodPost, urlStr, strings.NewReader(data.Encode())) // URL-encoded payload //req, err := http.NewRequest("POST", requestURL, bytes.NewBuffer(requestBody)) if err != nil { // handle error return "error", "error" }
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0") req.Header.Set("Accept", "application/json, text/javascript") req.Header.Set("Accept-Language", "en-US,en;q=0.5") // req.Header.Set("Accept-Encoding", "gzip, deflate") req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") req.Header.Set("X-Requested-With", "XMLHttpRequest") req.Header.Set("Connection", "keep-alive") req.Header.Set("Cookie", "session="+session) req.Header.Set("Referer", Referer) req.Header.Set("Pragma", "no-cache") req.Header.Set("Cache-Control", "no-cache")
req.Header.Set("X-Forward-For", randIp) req.Header.Set("HTTP_X_FORWARD_FOR", randIp) req.Header.Set("HTTP_CLIENT_IP", randIp) req.Header.Set("X-Real-IP", randIp) req.Header.Set("REMOTE_ADDR", randIp)
resp, err := httpClient.Do(req) if err != nil || resp.StatusCode == 403 || resp.StatusCode == 404 || resp.StatusCode == 503 { // handle error // 这两行打日志的生成时取消,不然会打很多日志 //logger.Println(err) //logger.Println(requestURL) return "error", "error" } defer resp.Body.Close() //body, err := gzip.NewReader(resp.Body) //result, _ := ioutil.ReadAll(body) result, err := ioutil.ReadAll(resp.Body) if err != nil { // handle error //logger.Println(err) return "error", "error" } return string(result), datas }
|