当前位置: 首页>>代码示例>>Golang>>正文


Golang CookieJar.SetCookies方法代码示例

本文整理汇总了Golang中net/http.CookieJar.SetCookies方法的典型用法代码示例。如果您正苦于以下问题:Golang CookieJar.SetCookies方法的具体用法?Golang CookieJar.SetCookies怎么用?Golang CookieJar.SetCookies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net/http.CookieJar的用法示例。


在下文中一共展示了CookieJar.SetCookies方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: parseCookies

// parseCookies set the sessionCookie via Javascript evaluation
func parseCookies(base *url.URL, js string, cookies http.CookieJar) {
	vm := otto.New()
	if result, err := vm.Run(js + "\nWEBVAR_JSONVAR_WEB_SESSION.WEBVAR_STRUCTNAME_WEB_SESSION[0].SESSION_COOKIE"); err == nil {
		cookie, _ := result.ToString()
		cookies.SetCookies(base, []*http.Cookie{{Name: "SessionCookie", Value: cookie}})
	} else {
		log.Fatalf("Error: %s\n", err)
	}
}
开发者ID:fayep,项目名称:console,代码行数:10,代码来源:main.go

示例2: SetCookie

// SetCookie sets a cookie for the given URL on the given cookie jar
// that will holds the given macaroon slice. The macaroon slice should
// contain a single primary macaroon in its first element, and any
// discharges after that.
func SetCookie(jar http.CookieJar, url *url.URL, ms macaroon.Slice) error {
	cookie, err := NewCookie(ms)
	if err != nil {
		return errgo.Mask(err)
	}
	// TODO verify that setting this for the URL makes it available
	// to all paths under that URL.
	jar.SetCookies(url, []*http.Cookie{cookie})
	return nil
}
开发者ID:cmars,项目名称:oo,代码行数:14,代码来源:client.go

示例3: SetCookie

// SetCookie creates a cookie in jar which is suitable for performing agent
// logins to u.
//
// If using SetUpAuth, it should not be necessary to use
// this function.
func SetCookie(jar http.CookieJar, u *url.URL, username string, pk *bakery.PublicKey) {
	al := agentLogin{
		Username:  username,
		PublicKey: pk,
	}
	b, err := json.Marshal(al)
	if err != nil {
		// This shouldn't happen as the agentLogin type has to be marshalable.
		panic(errgo.Notef(err, "cannot marshal cookie"))
	}
	v := base64.StdEncoding.EncodeToString(b)
	jar.SetCookies(u, []*http.Cookie{{
		Name:  cookieName,
		Value: v,
	}})
}
开发者ID:cmars,项目名称:oo,代码行数:21,代码来源:agent.go

示例4: cookie_process

func cookie_process(cookiejar http.CookieJar, surl string, cookiedata string) {
	if cookiedata == "" {
		return
	}
	cookiedata = "HTTP/1.0 200 OK\r\n" + cookiedata + "\r\n\r\n"
	req, err := http.NewRequest("GET", surl, nil)
	if err != nil {
		fmt.Println(err)
		return
	}
	res, err := http.ReadResponse(bufio.NewReader(strings.NewReader(cookiedata)), req)
	if err != nil {
		fmt.Println(err)
		return
	}
	cookies := res.Cookies()
	turl, err := url.Parse(surl)
	cookiejar.SetCookies(turl, cookies)
}
开发者ID:EMSL-MSC,项目名称:pacifica-auth,代码行数:19,代码来源:pacificaauth.go

示例5: Do

// Start a request, and get the response.
//
// Usually we just need the Get and Post method.
func (this *HttpClient) Do(method string, url string, headers map[string]string,
	body io.Reader) (*Response, error) {
	options := mergeOptions(defaultOptions, this.Options, this.oneTimeOptions)
	headers = mergeHeaders(this.Headers, this.oneTimeHeaders, headers)
	cookies := this.oneTimeCookies

	var transport http.RoundTripper
	var jar http.CookieJar
	var err error

	// transport
	if this.transport == nil || !this.reuseTransport {
		transport, err = prepareTransport(options)
		if err != nil {
			this.reset()
			return nil, err
		}

		if this.reuseTransport {
			this.transport = transport
		}
	} else {
		transport = this.transport
	}

	// jar
	if this.jar == nil || !this.reuseJar {
		jar, err = prepareJar(options)
		if err != nil {
			this.reset()
			return nil, err
		}

		if this.reuseJar {
			this.jar = jar
		}
	} else {
		jar = this.jar
	}

	// release lock
	this.reset()

	redirect, err := prepareRedirect(options)
	if err != nil {
		return nil, err
	}

	c := &http.Client{
		Transport:     transport,
		CheckRedirect: redirect,
		Jar:           jar,
	}

	req, err := prepareRequest(method, url, headers, body, options)
	if err != nil {
		return nil, err
	}

	if jar != nil {
		jar.SetCookies(req.URL, cookies)
	} else {
		for _, cookie := range cookies {
			req.AddCookie(cookie)
		}
	}

	res, err := c.Do(req)

	return &Response{res}, err
}
开发者ID:tingin,项目名称:go-httpclient,代码行数:74,代码来源:httpclient.go


注:本文中的net/http.CookieJar.SetCookies方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。