kreangkrai

thairath

Apr 14th, 2019
6,831
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.03 KB | None | 0 0
  1. func getThairath(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
  2.     urlReq := "https://www.thairath.co.th/home"
  3.  
  4.     req, err := http.NewRequest("GET", urlReq, nil)
  5.     if err != nil{
  6.         w.Write([]byte(err.Error()))
  7.     }
  8.  
  9.     req.Header.Add("authority", "www.thairath.co.th")
  10.     req.Header.Add("pragma", "no-cache")
  11.     req.Header.Add("cache-control", "no-cache,no-cache")
  12.     req.Header.Add("upgrade-insecure-requests", "1")
  13.     req.Header.Add("user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36")
  14.     req.Header.Add("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
  15.     req.Header.Add("accept-language", "en-US,en;q=0.9")
  16.  
  17.     res, err := http.DefaultClient.Do(req)
  18.     if err != nil{
  19.         w.Write([]byte(err.Error()))
  20.     }
  21.  
  22.     defer res.Body.Close()
  23.     body, err := ioutil.ReadAll(res.Body)
  24.     if err != nil{
  25.         w.Write([]byte(err.Error()))
  26.     }
  27.  
  28.     w.Write(body)
  29. }
Advertisement