本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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 ""
}
示例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
}
示例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.")
}
示例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),
}
}
示例10: getJar
func getJar() *cookiejar.Jar {
jar, err := cookiejar.New(nil)
if err != nil {
// Log
}
return jar
}
示例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
}
示例12: NewCookiejar
// 创建http.CookieJar类型的值
func NewCookiejar() http.CookieJar {
options := &cookiejar.Options{PublicSuffixList: &mk_publicSuffixList{}}
jar, _ := cookiejar.New(options)
return jar
}
示例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
}
示例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,
}
}
示例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()
}