Use go to write a proxy-like applet, can be used to access Goolge personal use or can.

Source: Internet
Author: User

Package Mainimport ("FMT" "io" "net/http") func Main () {http. Handlefunc ("/", route) E: = http. Listenandserve (": +", nil) if E! = nil {fmt. Println (e)}}func Route (W http. Responsewriter, R *http. Request) {req, _: = http. Newrequest (R.method, "", R.body) req. URL = R.urlreq.url.host = r.host//"www.qq.com" req. Url. Scheme = "http" for _, V: = Range r.cookies () {req. Addcookie (v)}//req. Header = R.header The header here will not be used, if used, he will automatically jump to HTTPS, the agent has a problem. RESP, err: = http. Defaultclient.do (req) If err! = Nil {fmt. Println ("Here:", err) Return}for k, V: = Range resp. Header {For _, Value: = Range v {w.header (). ADD (k, value)}}for _, Cookie: = Range resp. Cookies () {W.header (). ADD ("Set-cookie", cookies. Raw)}w.writeheader (resp. StatusCode) io. Copy (W, resp. Body) resp. Body.close () R.body.close ()}
This is used to visit overseas sites, to the local host, the domain name binding to IP, for example: 1.1.1.1 www.google.com

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Use go to write a proxy-like applet, can be used to access Goolge personal use or can.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.