Skip to content

Instantly share code, notes, and snippets.

@rikoudosenin
Created May 12, 2018 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rikoudosenin/af82fb65960773d93f47e4fae09adc98 to your computer and use it in GitHub Desktop.
Save rikoudosenin/af82fb65960773d93f47e4fae09adc98 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"strings"
"time"
)
func main() {
Url := "http://eu.httpbin.org/anything"
proxyUrl, _ := url.Parse("http://127.0.0.1:8888")
var netTransport = &http.Transport{
Dial: (&net.Dialer{
Timeout: 5 * time.Second,
}).Dial,
TLSHandshakeTimeout: 5 * time.Second,
Proxy: http.ProxyURL(proxyUrl),
}
c := &http.Client{
Timeout: 10 * time.Second,
Transport: netTransport,
}
headers := map[string]string{
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36",
"Upgrade-Insecure-Requests": "1",
"Connection": "keep-alive",
}
// postDATA := map[string]string{
// "This data": " is posted",
// "like": "this",
// }
// payload, _ := json.Marshal(postDATA)
// posting form data
form := url.Values{}
form.Add("Posting", "this")
req, _ := http.NewRequest("GET", Url, strings.NewReader(form.Encode()))
setHeaders(req, headers)
resp, _ := c.Do(req)
defer resp.Body.Close()
bytes, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(bytes))
}
func setHeaders(req *http.Request, m map[string]string) {
for key, value := range m {
req.Header.Add(key, value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment