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


Golang Client.Error方法代码示例

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


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

示例1: http_get

func http_get(url string) (res []byte) {
	req, _ := http.NewRequest("GET", url, nil)
	if SID != "" {
		req.AddCookie(&http.Cookie{Name: "sid", Value: SID})
	}
	r, er := new(http.Client).Do(req)
	if er != nil {
		println(url, er.Error())
		os.Exit(1)
	}
	if SID == "" {
		for i := range r.Cookies() {
			if r.Cookies()[i].Name == "sid" {
				SID = r.Cookies()[i].Value
				//fmt.Println("sid", SID)
			}
		}
	}
	if r.StatusCode == 200 {
		defer r.Body.Close()
		res, _ = ioutil.ReadAll(r.Body)
	} else {
		println(url, "http.Get returned code", r.StatusCode)
		os.Exit(1)
	}
	return
}
开发者ID:niniwzw,项目名称:gocoin,代码行数:27,代码来源:goc.go

示例2: Send

// Sends a notification to the GCM gateway.
func (this *Client) Send(n *Notification) string {
	req, _ := http.NewRequest("POST", this.Gateway, strings.NewReader(n.ToJSON()))
	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Authorization", "key="+this.ApiKey)
	resp, err := new(http.Client).Do(req)
	defer resp.Body.Close()
	if err != nil {
		return err.Error()
	}
	body, _ := ioutil.ReadAll(resp.Body)
	return string(body)
}
开发者ID:ridecharge,项目名称:gcm,代码行数:13,代码来源:client.go

示例3: Get

func Get(url string) (string, error) { // From http://stackoverflow.com/questions/11692860/how-can-i-efficiently-download-a-large-file-using-go
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return "", fmt.Errorf("Request creation error: %s", err.Error())
	}
	req.Header.Set("User-Agent", UserAgent)
	resp, err := new(http.Client).Do(req)
	if err != nil {
		return "", fmt.Errorf("HTTP request error: %s", err.Error())
	}
	defer resp.Body.Close()
	buf := new(bytes.Buffer)
	_, err = io.Copy(buf, resp.Body)
	if err != nil {
		return "", fmt.Errorf("Buffer copy error: %s", err.Error())
	}
	return string(buf.Bytes()), nil
}
开发者ID:Team-IVIag,项目名称:IVIag-go,代码行数:18,代码来源:iviag.go

示例4: HandleGet

func (this *WebAppServer) HandleGet(w http.ResponseWriter, request *http.Request) {
	URL := this.WebAppURL + request.URL.Path
	if request.URL.RawQuery != "" {
		URL += "?" + request.URL.RawQuery
	}
	req, err := http.NewRequest(request.Method, URL, request.Body)
	if err != nil {
		w.WriteHeader(500)
		fmt.Fprint(w, "bab error :(", err.Error())
		return
	}
	this.copyHeader(request.Header, req.Header)
	resp, err := new(http.Client).Do(req)
	if err != nil {
		w.WriteHeader(500)
		fmt.Fprint(w, "bab error :(\n", err.Error())
		return
	}
	this.copyHeader(resp.Header, w.Header())
	w.WriteHeader(resp.StatusCode)
	defer resp.Body.Close()
	io.Copy(w, resp.Body)
}
开发者ID:didiercrunch,项目名称:bab,代码行数:23,代码来源:webappserver.go

示例5: GetPics

func GetPics(archive uint64) (rawhtml string, urls []string, err error) {
	req, err := http.NewRequest("GET", ArchivePrefix+strconv.FormatUint(archive, 10), nil)
	if err != nil {
		return "", nil, fmt.Errorf("Request creation error: %s", err.Error())
	}
	req.Header.Set("User-Agent", UserAgent)
	func() {
		CookieLock.RLock()
		defer CookieLock.RUnlock()
		req.AddCookie(&Cookie)
	}()
	resp, err := new(http.Client).Do(req)
	if err != nil {
		return "", nil, fmt.Errorf("HTTP request error: %s", err.Error())
	}
	defer resp.Body.Close()
	buf := new(bytes.Buffer)
	io.Copy(buf, resp.Body)
	rawhtml = buf.String()
	var doc *goquery.Document
	doc, err = goquery.NewDocumentFromReader(buf)
	if err != nil {
		return
	}
	if doc.Find("title").First().Text()[:7] == "You are" {
		UpdateCookie(doc)
		return GetPics(archive)
	}
	urls = make([]string, 0)
	doc.Find("div .entry-content").Find("img").Each(func(i int, s *goquery.Selection) {
		if img, ok := s.Attr("data-lazy-src"); ok {
			urls = append(urls, img)
		}
	})
	return
}
开发者ID:Team-IVIag,项目名称:IVIag-go,代码行数:36,代码来源:iviag.go

示例6: GetArchives

func GetArchives(manga uint64) (title string, mangas []Archive, err error) {
	req, err := http.NewRequest("GET", MangaPrefix+strconv.FormatUint(manga, 10), nil)
	if err != nil {
		return "", nil, fmt.Errorf("Request creation error: %s", err.Error())
	}
	req.Header.Set("User-Agent", UserAgent)
	func() {
		CookieLock.RLock()
		defer CookieLock.RUnlock()
		req.AddCookie(&Cookie)
	}()
	resp, err := new(http.Client).Do(req)
	if err != nil {
		return "", nil, fmt.Errorf("HTTP request error: %s", err.Error())
	}
	defer resp.Body.Close()
	buf := new(bytes.Buffer)
	io.Copy(buf, resp.Body)
	var doc *goquery.Document
	doc, err = goquery.NewDocumentFromReader(buf)
	if err != nil {
		return
	}
	if doc.Find("title").First().Text()[:7] == "You are" {
		UpdateCookie(doc)
		return GetArchives(manga)
	}
	links := make([]Archive, 0)
	seq := uint64(1)
	title = Filter(doc.Find("div .subject").Find("h1").Text(), "_")
	if title == "" {
		title = Filter(strings.Replace(doc.Find("title").First().Text(), " | SHENCOMICS", "", 1), "_")
		if title == "" {
			title = "Untitled"
		}
	}
	needFix := make(map[uint64]*struct {
		needs []int
		fix   int
	})
	doc.Find("div .content").Children().Find("a").Each(func(i int, s *goquery.Selection) {
		if l, ok := s.Attr("href"); ok && strings.Index(l, ArchivePrefix) != -1 {
			if link, err := strconv.ParseUint(l[strings.Index(l, ArchivePrefix)+len(ArchivePrefix):], 10, 64); err == nil {
				sub := regexp.MustCompile("^[\xc2\xa0 \\t]+").ReplaceAllString(s.Text(), "")
				if sub == "" {
					for _, l := range links {
						if l.ID == link {
							return
						}
					}
					sub = "Untitled"
					if _, ok := needFix[link]; ok {
						needFix[link].needs = append(needFix[link].needs, len(links))
					} else {
						needFix[link] = &struct {
							needs []int
							fix   int
						}{
							[]int{len(links)},
							-1,
						}
					}
				} else {
					if index, ok := needFix[link]; ok && index.fix < 0 {
						needFix[link].fix = len(links)
					}
				}
				links = append(links, Archive{
					ID:      link,
					Seq:     seq,
					Title:   fmt.Sprintf("%s(%d)", title, manga),
					Subject: sub,
				})
				seq++
			}
		}
	})
	for _, st := range needFix {
		if st.fix > 0 {
			for _, need := range st.needs {
				links[need].Subject = links[st.fix].Subject
			}
		}
	}
	return title, links, nil
}
开发者ID:Team-IVIag,项目名称:IVIag-go,代码行数:86,代码来源:iviag.go


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