当前位置: 首页>>代码示例>>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;未经允许,请勿转载。