本文整理汇总了Golang中ml/net/http.Session类的典型用法代码示例。如果您正苦于以下问题:Golang Session类的具体用法?Golang Session怎么用?Golang Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: login
func login(session *http.Session, user, pass String) error {
resp, err := session.Post(
"http://bbs.saraba1st.com/2b/member.php",
Dict{
"params": Dict{
"mod": "logging",
"action": "login",
"loginsubmit": "yes",
"infloat": "yes",
"lssubmit": "yes",
"inajax": "1",
},
"body": Dict{
"fastloginfield": "username",
"quickforward": "yes",
"handlekey": "ls",
"username": user,
"password": pass,
},
"encoding": strings.CP_UTF8,
},
)
if err != nil {
return err
}
if resp.StatusCode != http.StatusOK {
return Errorf("login status: %s", http.StatusText(resp.StatusCode))
}
return nil
}
示例2: openThread
func openThread(session *http.Session, user String) {
doc := openPage(session, FORUM_URL)
threads := []*goquery.Selection{}
doc.Find("tbody").Each(func(i int, s *goquery.Selection) {
id_, exist := s.Attr("id")
id := String(id_)
if exist && id.StartsWith("normalthread_") {
threads = append(threads, s)
}
})
if len(threads) == 0 {
Raise("empty thread")
}
index := random.IntRange(0, len(threads))
t := threads[index].Find("a.s.xst")
href, ok := t.Attr("href")
if ok == false {
Raise("can't find thread addr")
}
credit := String(doc.Find("#extcreditmenu").Text())
console.SetTitle(credit.Split(":", 1)[1])
Printf("[%s][%s] %s @ %s\n", time.Now().Format("2006-01-02 15:04:05"), user, credit, t.Text())
session.Get(BASE_URL + href)
}
示例3: openPage
func openPage(session *http.Session, url String) (doc *goquery.Document) {
resp := session.Get(url)
doc, err := goquery.NewDocumentFromReader(strings.Decode(resp.Content, resp.Encoding).NewReader())
RaiseIf(err)
return
}
示例4: openPage
func openPage(session *http.Session, url String) (doc *goquery.Document, err error) {
resp, err := session.Get(url)
if err != nil {
return nil, err
}
doc, err = goquery.NewDocumentFromReader(strings.Decode(resp.Content, resp.Encoding).NewReader())
return
}
示例5: logout
func logout(session *http.Session) {
doc := openPage(session, FORUM_URL)
doc.Find("a").Each(func(i int, s *goquery.Selection) {
href_, exist := s.Attr("href")
href := String(href_)
if exist && href.Contains("action=logout") {
session.Get(BASE_URL + href)
}
})
}
示例6: logout
func logout(session *http.Session) error {
doc, err := openPage(session, FORUM_URL)
if err != nil {
return err
}
doc.Find("a").Each(func(i int, s *goquery.Selection) {
href_, exist := s.Attr("href")
href := String(href_)
if exist && href.Contains("action=logout") {
session.Get(BASE_URL + href)
}
})
return nil
// logout = logout and page.find(lambda e : e.get('href') and 'action=logout' in e['href'])
// if logout:
// yield from http.request('get', BASE_URL + logout['href'])
}