當前位置: 首頁>>代碼示例>>Golang>>正文


Golang cookiejar.New函數代碼示例

本文整理匯總了Golang中net/http/cookiejar.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewClient

func NewClient() (client *http.Client) {
	client = new(http.Client)
	client.Transport = DefaultTransport
	DefaultTransport.CloseIdleConnections()
	client.Jar, _ = cookiejar.New(options)
	return
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:7,代碼來源:controller.go

示例2: New

// Used to create a new SuperAgent object.
func New() *SuperAgent {
	cookiejarOptions := cookiejar.Options{
		PublicSuffixList: publicsuffix.List,
	}
	jar, _ := cookiejar.New(&cookiejarOptions)
	s := &SuperAgent{
		TargetType:        "json",
		Data:              make(map[string]interface{}),
		Header:            make(map[string]string),
		RawString:         "",
		SliceData:         []interface{}{},
		FormData:          url.Values{},
		QueryData:         url.Values{},
		BounceToRawString: false,
		Client:            &http.Client{Jar: jar},
		Transport:         &http.Transport{},
		Cookies:           make([]*http.Cookie, 0),
		Errors:            nil,
		BasicAuth:         struct{ Username, Password string }{},
		Debug:             false,
		CurlCommand:       false,
		logger:            log.New(os.Stderr, "[gorequest]", log.LstdFlags),
	}
	// desable keep alives by default, see this issue https://github.com/parnurzeal/gorequest/issues/75
	s.Transport.DisableKeepAlives = true
	return s
}
開發者ID:moul,項目名稱:ssh2docker,代碼行數:28,代碼來源:main.go

示例3: New

// Used to create a new SuperAgent object.
func New() *SuperAgent {
	cookiejarOptions := cookiejar.Options{
		PublicSuffixList: publicsuffix.List,
	}
	jar, _ := cookiejar.New(&cookiejarOptions)
	s := &SuperAgent{
		TargetType:        "json",
		Data:              make(map[string]interface{}),
		Header:            make(map[string]string),
		RawString:         "",
		SliceData:         []interface{}{},
		FormData:          url.Values{},
		QueryData:         url.Values{},
		BounceToRawString: false,
		Client:            &http.Client{Jar: jar},
		Transport:         &http.Transport{},
		Cookies:           make([]*http.Cookie, 0),
		Errors:            nil,
		BasicAuth:         struct{ Username, Password string }{},
		Debug:             false,
		CurlCommand:       false,
		logger:            log.New(os.Stderr, "[gorequest]", log.LstdFlags),
	}
	return s
}
開發者ID:archsaber,項目名稱:gorequest,代碼行數:26,代碼來源:main.go

示例4: New

func New(opts map[string]interface{}) *Cli {
	homedir := homedir()
	cookieJar, _ := cookiejar.New(nil)
	endpoint, _ := opts["endpoint"].(string)
	url, _ := url.Parse(strings.TrimRight(endpoint, "/"))

	transport := &http.Transport{
		TLSClientConfig: &tls.Config{},
	}

	if project, ok := opts["project"].(string); ok {
		opts["project"] = strings.ToUpper(project)
	}

	if insecureSkipVerify, ok := opts["insecure"].(bool); ok {
		transport.TLSClientConfig.InsecureSkipVerify = insecureSkipVerify
	}

	cli := &Cli{
		endpoint:   url,
		opts:       opts,
		cookieFile: filepath.Join(homedir, ".jira.d", "cookies.js"),
		ua: &http.Client{
			Jar:       cookieJar,
			Transport: transport,
		},
	}

	cli.ua.Jar.SetCookies(url, cli.loadCookies())

	return cli
}
開發者ID:RC1140,項目名稱:go-jira,代碼行數:32,代碼來源:cli.go

示例5: Login

func (p *PTPSearch) Login() error {
	options := cookiejar.Options{
		PublicSuffixList: publicsuffix.List,
	}
	var err error
	p.Cookiejar, err = cookiejar.New(&options)
	if err != nil {
		return err
	}

	client := &http.Client{Jar: p.Cookiejar}
	postData := url.Values{"username": {p.username},
		"password": {p.password}, "passkey": {p.passkey}, "keeplogged": {"1"}}
	resp, err := client.PostForm(ptp_endpoint_tls+"/ajax.php?action=login",
		postData)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	contents, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}

	var result loginResult
	if err := json.Unmarshal(contents, &result); err != nil {
		return err
	}
	if result.Result != "Ok" {
		return errors.New("Could not login to PTP.")
	}
	return nil
}
開發者ID:huangbong,項目名稱:broadcasthepopcorn,代碼行數:34,代碼來源:ptp_search.go

示例6: GetLanIP_Openwrt

func GetLanIP_Openwrt(address, password string) string {
	// Login first
	jar, _ := cookiejar.New(nil)
	client := &http.Client{Jar: jar}
	res, err := client.PostForm("http://"+address+"/", url.Values{"luci_username": {"root"}, "luci_password": {password}})
	if err != nil {
		fmt.Println(err)
		return ""
	}
	bin, _ := ioutil.ReadAll(res.Body)
	res.Body.Close()
	str := string(bin)
	ex := regexp.MustCompile(`/cgi-bin/luci/;stok=([a-z0-9]{32})`) // /cgi-bin/luci/;stok=dfc41c0ba4035a36922a6df4e26f6dd7/
	li := ex.FindStringSubmatch(str)
	if len(li) > 1 {
		res, err = client.Get("http://" + address + li[0] + "?status=1")
		if err != nil {
			fmt.Println(err)
			return ""
		}
		bin, _ = ioutil.ReadAll(res.Body)
		res.Body.Close()
		str = string(bin)
		ex = regexp.MustCompile(`"ipaddr":"(10\.[\.0-9]+?)",`)
		li = ex.FindStringSubmatch(str)
		if len(li) > 1 {
			return li[1]
		}
	}
	return ""
}
開發者ID:pa001024,項目名稱:netdialer,代碼行數:31,代碼來源:openwrt_cli.go

示例7: NewSession

// TODO(tiborvass): remove authConfig param once registry client v2 is vendored
func NewSession(client *http.Client, authConfig *cliconfig.AuthConfig, endpoint *Endpoint) (r *Session, err error) {
	r = &Session{
		authConfig:    authConfig,
		client:        client,
		indexEndpoint: endpoint,
	}

	var alwaysSetBasicAuth bool

	// If we're working with a standalone private registry over HTTPS, send Basic Auth headers
	// alongside all our requests.
	if endpoint.VersionString(1) != IndexServerAddress() && endpoint.URL.Scheme == "https" {
		info, err := endpoint.Ping()
		if err != nil {
			return nil, err
		}

		if info.Standalone && authConfig != nil {
			logrus.Debugf("Endpoint %s is eligible for private registry. Enabling decorator.", endpoint.String())
			alwaysSetBasicAuth = true
		}
	}

	// Annotate the transport unconditionally so that v2 can
	// properly fallback on v1 when an image is not found.
	client.Transport = AuthTransport(client.Transport, authConfig, alwaysSetBasicAuth)

	jar, err := cookiejar.New(nil)
	if err != nil {
		return nil, errors.New("cookiejar.New is not supposed to return an error")
	}
	client.Jar = jar

	return r, nil
}
開發者ID:AdamOssenford,項目名稱:docker-pi,代碼行數:36,代碼來源:session.go

示例8: Run

func (cmd *Cancel) Run() {
	log.SetOutput(LogOutput())

	if *cmd.VisitID == "" {
		fmt.Println("Must specify visitid.")
		return
	}

	// Load session
	mboSession, err := LoadMBOSession()
	if err != nil {
		fmt.Println(err)
		return
	}
	cookieJar, _ := cookiejar.New(nil)
	client := &http.Client{Jar: cookieJar}
	mbo_url, _ := url.Parse(MBO_URL)
	client.Jar.SetCookies(mbo_url, mboSession.Cookies)

	resp, err := client.Get(fmt.Sprintf("%s/ASP/adm/adm_res_canc.asp?visitID=%s&cType=1", MBO_URL, *cmd.VisitID))
	if err != nil || resp.StatusCode != 200 {
		log.Println(err)
		log.Println(resp)
		fmt.Println("Error performing cancel.")
	}
	defer resp.Body.Close()

	fmt.Println("Cancelled visit.")
}
開發者ID:rgarcia,項目名稱:mbo,代碼行數:29,代碼來源:cancel.go

示例9: NewTestSuite

// NewTestSuite returns an initialized TestSuite ready for use. It is invoked
// by the test harness to initialize the embedded field in application tests.
func NewTestSuite() TestSuite {
	jar, _ := cookiejar.New(nil)
	return TestSuite{
		Client:  &http.Client{Jar: jar},
		Session: make(Session),
	}
}
開發者ID:Elido,項目名稱:revel,代碼行數:9,代碼來源:tests.go

示例10: getJar

func getJar() *cookiejar.Jar {
	jar, err := cookiejar.New(nil)
	if err != nil {
		// Log
	}
	return jar
}
開發者ID:jwulf,項目名稱:zedlist,代碼行數:7,代碼來源:api_test.go

示例11: NewClient

func NewClient(u *url.URL, insecure bool) *Client {
	c := Client{
		u: u,
		k: insecure,
		d: newDebug(),
	}

	// Initialize http.RoundTripper on client, so we can customize it below
	c.t = &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		Dial: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}).Dial,
	}

	if c.u.Scheme == "https" {
		c.t.TLSClientConfig = &tls.Config{InsecureSkipVerify: c.k}
		c.t.TLSHandshakeTimeout = 10 * time.Second
	}

	c.Client.Transport = c.t
	c.Client.Jar, _ = cookiejar.New(nil)

	// Remove user information from a copy of the URL
	c.u = c.URL()
	c.u.User = nil

	return &c
}
開發者ID:hickeng,項目名稱:govmomi,代碼行數:30,代碼來源:client.go

示例12: NewCookiejar

// 創建http.CookieJar類型的值
func NewCookiejar() http.CookieJar {
	options := &cookiejar.Options{PublicSuffixList: &mk_publicSuffixList{}}

	jar, _ := cookiejar.New(options)

	return jar
}
開發者ID:MinyaKonka,項目名稱:MKWebCrawler,代碼行數:8,代碼來源:cookiejar.go

示例13: CreateDefaultHTTPClient

// CreateDefaultHTTPClient creates default HTTP with cookie jar.
func CreateDefaultHTTPClient() (*http.Client, error) {
	jar, err := cookiejar.New(nil)
	if err != nil {
		return nil, err
	}
	return &http.Client{Jar: jar}, nil
}
開發者ID:jbub,項目名稱:savey,代碼行數:8,代碼來源:client.go

示例14: NewSession

func NewSession() *Session {
	jar, err := cookiejar.New(nil)
	if err != nil {
		RaiseHttpError(err)
	}

	defaultTransport := &gohttp.Transport{
		Proxy: nil,
		// DisableKeepAlives   : true,
		Dial: (&gonet.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}).Dial,

		TLSHandshakeTimeout: 10 * time.Second,
	}

	client := &gohttp.Client{
		CheckRedirect: nil,
		Jar:           jar,
		Timeout:       30 * time.Second,
		Transport:     defaultTransport,
	}

	return &Session{
		cookie:           jar,
		client:           client,
		headers:          make(gohttp.Header),
		defaultTransport: defaultTransport,
	}
}
開發者ID:acgngca,項目名稱:Arianrhod,代碼行數:31,代碼來源:session.go

示例15: ExampleNew

func ExampleNew() {
	jar, err := cookiejar.New(nil)
	if err != nil {
		log.Fatal(err)
	}
	client := http.DefaultClient
	client.Jar = jar

	// Wrap around the client's transport to add support for space cookies.
	client.Transport = New(client.Transport, jar)

	// Assuming example.com sets space cookies, they get added to the jar.
	resp, err := client.Get("https://example.com")
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	// So that following requests carry these cookies.
	resp, err = client.Get("https://example.com")
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()
}
開發者ID:jhautefeuille,項目名稱:misc,代碼行數:25,代碼來源:spacecookies_test.go


注:本文中的net/http/cookiejar.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。