Golang HTTP Cookie Login Baidu

Source: Internet
Author: User
Tags http cookie
This is a creation in Article, where the information may have evolved or changed. "Package main//thanks to the help of friends//qq29295842 welcome Everyone Technical Exchange import (" FMT "" Io/ioutil "" Net/http "" Net/http/cookiejar "/" OS "" Net/url "Time") Func main () {//init Jarj, _: = Cookiejar. New (nil)//Create clientclient: = &http. client{jar:j}//Create requestreq, err: = http. Newrequest ("GET", "http://zhanzhang.baidu.com", nil)//Fetch Requestresp, err: = client. Do (req) if err! = Nil {fmt. Println ("Failure:", err)}//start modifying the value inside the cache jar var clist []*http. Cookieclist = Append (CList, &http. Cookie{name: "Bduss", Domain: ". Baidu.com", Path: "/", Value: "Cookie value xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", Expires:time. Now (). Adddate (1, 0, 0),}) Urlx, _: = URL. Parse ("http://zhanzhang.baidu.com") j.setcookies (URLX, CList) fmt. Printf ("Jar Cookie:%v", J.cookies (URLX))//Fetch Requestresp, err = client. Do (req) if err! = Nil {fmt. Println ("Failure:", err)}//Read Response Bodyrespbody, _: = Ioutil. ReadAll (resp. Body)//Display resultsfmt.println ("Response Status:", resp. Status) fmt. PRINTLN ("Response HeadERs: ", resp. Header) fmt. PRINTLN ("Response Body:", String (respbody)) fmt. Printf ("Response Cookies:%v", resp. Cookies ())} '! [A1.png] (https://static.studygolang.com/170901/4dc8804990d4897dccc65161c11b39d8.png) 672 reads  
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.