示例#1
0
func (self *HttpDownloader) Download(req *context.Request) *context.Response {
	var mtype string
	var p = context.NewResponse(req)
	mtype = req.GetRespType()
	switch mtype {
	case "html":
		return self.downloadHtml(p, req)
	case "json":
		fallthrough
	case "jsonp":
		return self.downloadJson(p, req)
	case "text":
		return self.downloadText(p, req)
	default:
		reporter.Log.Println("error request type:" + mtype)
	}
	return p
}
示例#2
0
func (self *Surfer) Download(cReq *context.Request) *context.Response {
	cResp := context.NewResponse(nil)

	resp, err := self.download.Download(cReq.GetMethod(), cReq.GetUrl(), cReq.GetReferer(), cReq.GetPostData(), cReq.GetHeader(), cReq.GetCookies())

	cResp.SetRequest(cReq)

	if err != nil {
		cResp.SetStatus(true, err.Error())
		return cResp
	}

	// get converter to utf-8
	body := self.changeCharsetEncodingAuto(resp.Body, resp.Header.Get("Content-Type"))
	//fmt.Printf("utf-8 body %v \r\n", bodyStr)
	defer resp.Body.Close()
	cResp.SetText(body)
	cResp.SetStatus(false, "")
	return cResp
}