requests

package
v0.0.0-...-b1b21d8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2023 License: LGPL-3.0 Imports: 29 Imported by: 1

README

Function Overview

  • Cookie switch, connection pool switch, HTTP/2, JA3
  • Self-implemented SOCKS5, HTTP proxy, HTTPS proxy
  • Automatic decompression and decoding
  • DNS caching
  • Automatic type conversion
  • Retry attempts, request callbacks
  • WebSocket protocol
  • SSE protocol

Setting Proxies

Proxy Setting Priority

Global proxy method < Global proxy string < Local proxy string

Set and Modify Global Proxy Method (Only called when creating a new connection, not called when reusing connections)

package main

import (
    "log"

    "gitee.com/baixudong/gospider/requests"
)

func main() {
	reqCli, err := requests.NewClient(nil, requests.ClientOption{
		GetProxy: func(ctx context.Context, url *url.URL) (string, error) { // Set global proxy method
			return "http://127.0.0.1:7005", nil
		}})
	if err != nil {
		log.Panic(err)
	}
	response, err := reqCli.Request(nil, "get", "http://myip.top") // Send GET request
	if err != nil {
		log.Panic(err)
	}
	reqCli.SetGetProxy(func(ctx context.Context, url *url.URL) (string, error) { // Modify global proxy method
		return "http://127.0.0.1:7006", nil
	})
	log.Print(response.Text()) // Get content and parse as string
}

Set and Modify Global Proxy

package main

import (
    "log"

    "gitee.com/baixudong/gospider/requests"
)

func main() {
	reqCli, err := requests.NewClient(nil, requests.ClientOption{
		Proxy: "http://127.0.0.1:7005", // Set global proxy
	})
	if err != nil {
		log.Panic(err)
	}
	response, err := reqCli.Request(nil, "get", "http://myip.top") // Send GET request
	if err != nil {
		log.Panic(err)
	}
	err = reqCli.SetProxy("http://127.0.0.1:7006") // Modify global proxy
	if err != nil {
		log.Panic(err)
	}
	log.Print(response.Text()) // Get content and parse as string
}

Set Local Proxy

package main

import (
    "log"

    "gitee.com/baixudong/gospider/requests"
)

func main() {
	reqCli, err := requests.NewClient(nil)
	if err != nil {
		log.Panic(err)
	}
	response, err := reqCli.Request(nil, "get", "http://myip.top", requests.RequestOption{
		Proxy: "http://127.0.0.1:7005",
	})
	if err != nil {
		log.Panic(err)
	}
	log.Print(response.Text()) // Get content and parse as string
}

Force Close Proxy and Use Local Network

package main

import (
    "log"

    "gitee.com/baixudong/gospider/requests"
)

func main() {
	reqCli, err := requests.NewClient(nil)
	if err != nil {
		log.Panic(err)
	}
	response, err := reqCli.Request(nil, "get", "http://myip.top", requests.RequestOption{
		DisProxy: true, // Force using local proxy
	})
	if err != nil {
		log.Panic(err)
	}
	log.Print(response.Text()) // Get content and parse as string
}

Sending HTTP Requests

package main

import (
    "log"

    "gitee.com/baixudong/gospider/requests"
)

func main() {
    reqCli, err := requests.NewClient(nil) // Create request client
    if err != nil {
        log.Panic(err)
    }
    response, err := reqCli.Request(nil, "get", "http://myip.top") // Send GET request
    if err != nil {
        log.Panic(err)
    }
    log.Print(response.Text())    // Get content and parse as string
    log.Print(response.Content()) // Get content as bytes
    log.Print(response.Json())    // Get JSON and parse with gjson
    log.Print(response.Html())    // Get content and parse as DOM
    log.Print(response.Cookies()) // Get cookies
}

Sending WebSocket Requests

package main

import (
	"context"
	"log"

	"gitee.com/baixudong/gospider/requests"
	"gitee.com/baixudong/gospider/websocket"
)

func main() {
	reqCli, err := requests.NewClient(nil) // Create request client
	if err != nil {
		log.Panic(err)
	}
	response, err := reqCli.Request(nil, "get", "ws://82.157.123.54:9010/ajaxchattest", requests.RequestOption{Headers: map[string]string{
		"Origin": "http://coolaf.com",
	}}) // Send WebSocket request
	if err != nil {
		log.Panic(err)
	}
	defer response.Close()
	wsCli := response.WebSocket()
	wsCli.SetReadLimit(1024 * 1024 * 1024) // Set maximum read limit
	if err = wsCli.Send(context.TODO(), websocket.MessageText, "测试"); err != nil { // Send text message
		log.Panic(err)
	}
	msgType, con, err := wsCli.Recv(context.TODO()) // Receive message
	if err != nil {
		log.Panic(err)
	}
	log.Print(msgType)     // Message type
	log.Print(string(con)) // Message content
}

IPv4, IPv6 Address Control Parsing

func main() {
	reqCli, err := requests.NewClient(nil, requests.ClientOption{
		AddrType: requests.Ipv4, // Prioritize parsing IPv4 addresses
		// AddrType: requests.Ipv6, // Prioritize parsing IPv6 addresses
	})
	if err != nil {
		log.Panic(err)
	}
	href := "https://test.ipw.cn"
	resp, err := reqCli.Request(nil, "get", href)
	if err != nil {
		log.Panic(err)
	}
	log.Print(resp.Text())
	log.Print(resp.StatusCode())
}

Forge JA3 Fingerprints

Generate Fingerprint from String

func main() {
	ja3Str := "772,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-13-18-51-45-43-27-17513,29-23-24,0"
	Ja3Spec, err := ja3.CreateSpecWithStr(ja3Str) // Generate fingerprint from string
	if err != nil {
		log.Panic(err)
	}
	reqCli, err := requests.NewClient(nil, requests.ClientOption{Ja3Spec: Ja3Spec})
	if err != nil {
		log.Panic(err)
	}
	response, err := reqCli.Request(nil, "get", "https://tools.scrapfly.io/api/fp/ja3?extended=1")
	if err != nil {
		log.Panic(err)
	}
	jsonData,_:=response.Json()
	log.Print(jsonData.Get("ja3").String())
	log.Print(jsonData.Get("ja3").String() == ja3Str)
}

Generate Fingerprint from ID

func main() {
	Ja3Spec, err := ja3.CreateSpecWithId(ja3.HelloChrome_Auto) // Generate fingerprint from ID
	if err != nil {
		log.Panic(err)
	}
	reqCli, err := requests.NewClient(nil, requests.ClientOption{Ja3Spec: Ja3Spec})
	if err != nil {
		log.Panic(err)
	}
	response, err := reqCli.Request(nil, "get", "https://tools.scrapfly.io/api/fp/ja3?extended=1")
	if err != nil {
		log.Panic(err)
	}
	jsonData,_:=response.Json()
	log.Print(jsonData.Get("ja3").String())
}

JA3 Switch

func main() {
	reqCli, err := requests.NewClient(nil)
	if err != nil {
		log.Panic(err)
	}
	response, err := reqCli.Request(nil, "get", "https://tools.scrapfly.io/api/fp/ja3?extended=1", requests.RequestOption{Ja3: true}) // Use the latest Chrome fingerprint
	if err != nil {
		log.Panic(err)
	}
	jsonData,_:=response.Json()
	log.Print(jsonData.Get("ja3").String())
}

H2 Fingerprint Switch

func main() {
	reqCli, err := requests.NewClient(nil, requests.ClientOption{
		H2Ja3: true,
	})
	if err != nil {
		log.Panic(err)
	}
	href := "https://tools.scrapfly.io/api/fp/anything"
	resp, err := reqCli.Request(nil, "get", href)
	if err != nil {
		log.Panic(err)
	}
	log.Print(resp.Text())
}

Modify H2 Fingerprint

func main() {
	reqCli, err := requests.NewClient(nil, requests.ClientOption{
		H2Ja3Spec: ja3.H2Ja3Spec{
			InitialSetting: []ja3.Setting{
				{Id: 1, Val: 65555},
				{Id: 2, Val: 1},
				{Id: 3, Val: 2000},
				{Id: 4, Val: 6291457},
				{Id: 6, Val: 262145},
			},
			ConnFlow: 15663106,
			OrderHeaders: []string{
				":method",
				":path",
				":scheme",
				":authority",
			},
		},
	})
	if err != nil {
		log.Panic(err)
	}
	href := "https://tools.scrapfly.io/api/fp/anything"
	resp, err := reqCli.Request(nil, "get", href)
	if err != nil {
		log.Panic(err)
	}
	log.Print(resp.Text())
}

Collecting Title of List Pages from National Public Resource Website and China Government Procurement Website

package main
import (
	"log"
	"gitee.com/baixudong/gospider/requests"
)
func main() {
	reqCli, err := requests.NewClient(nil)
	if err != nil {
		log.Panic(err)
	}
	resp, err := reqCli.Request(nil, "get", "http://www.ccgp.gov.cn/cggg/zygg/")
	if err != nil {
		log.Panic(err)
	}
	html := resp.Html()
	lis := html.Finds("ul.c_list_bid li")
	for _, li := range lis {
		title := li.Find("a").Get("title")
		log.Print(title)
	}
	resp, err = reqCli.Request(nil, "post", "http://deal.ggzy.gov.cn/ds/deal/dealList_find.jsp", requests.RequestOption{
		Data: map[string]string{
			"TIMEBEGIN_SHOW": "2023-04-26",
			"TIMEEND_SHOW":   "2023-05-05",
			"TIMEBEGIN":      "2023-04-26",
			"TIMEEND":        "2023-05-05",
			"SOURCE_TYPE":    "1",
			"DEAL_TIME":      "02",
			"DEAL_CLASSIFY":  "01",
			"DEAL_STAGE":     "0100",
			"DEAL_PROVINCE":  "0",
			"DEAL_CITY":      "0",
			"DEAL_PLATFORM":  "0",
			"BID_PLATFORM":   "0",
			"DEAL_TRADE":     "0",
			"isShowAll":      "1",
			"PAGENUMBER":     "2",
			"FINDTXT":        "",
		},
	})
	if err != nil {
		log.Panic(err)
	}
	jsonData,_ := resp.Json()
	lls := jsonData.Get("data").Array()
	for _, ll := range lls {
		log.Print(ll.Get("title"))
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AcceptLanguage = `"zh-CN,zh;q=0.9"`
View Source
var (
	ErrFatal = errors.New("致命错误")
)
View Source
var UserAgent = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36`

Functions

func DefaultHeaders

func DefaultHeaders() http.Header

请求操作========================================================================= start

func ReadRequest

func ReadRequest(b *bufio.Reader) (*http.Request, error)

Types

type AddrType

type AddrType int
const (
	Auto AddrType = 0
	Ipv4 AddrType = 4
	Ipv6 AddrType = 6
)

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(preCtx context.Context, options ...ClientOption) (*Client, error)

新建一个请求客户端,发送请求必须创建哈

func (*Client) ClearCookies

func (obj *Client) ClearCookies()

清除cookies

func (*Client) Close

func (obj *Client) Close()

关闭客户端

func (*Client) CloseIdleConnections

func (obj *Client) CloseIdleConnections()

关闭客户端中的空闲连接

func (*Client) Connect

func (obj *Client) Connect(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func (*Client) Cookies

func (obj *Client) Cookies(href string, cookies ...any) (Cookies, error)

返回url 的cookies,也可以设置url 的cookies

func (*Client) Delete

func (obj *Client) Delete(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func (*Client) Get

func (obj *Client) Get(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func (*Client) Head

func (obj *Client) Head(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func (*Client) Options

func (obj *Client) Options(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func (*Client) Patch

func (obj *Client) Patch(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func (*Client) Post

func (obj *Client) Post(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func (*Client) Put

func (obj *Client) Put(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func (*Client) Request

func (obj *Client) Request(preCtx context.Context, method string, href string, options ...RequestOption) (resp *Response, err error)

发送请求

func (*Client) SetGetProxy

func (obj *Client) SetGetProxy(getProxy func(ctx context.Context, url *url.URL) (string, error))

func (*Client) SetProxy

func (obj *Client) SetProxy(proxy string) error

func (*Client) Trace

func (obj *Client) Trace(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

type ClientOption

type ClientOption struct {
	GetProxy              func(ctx context.Context, url *url.URL) (string, error) //根据url 返回代理,支持https,http,socks5 代理协议
	Proxy                 string                                                  //设置代理,支持https,http,socks5 代理协议
	TLSHandshakeTimeout   time.Duration                                           //tls 超时时间,default:15
	ResponseHeaderTimeout time.Duration                                           //第一个response headers 接收超时时间,default:30
	DisCookie             bool                                                    //关闭cookies管理
	DisCompression        bool                                                    //关闭请求头中的压缩功能
	LocalAddr             string                                                  //本地网卡出口ip
	IdleConnTimeout       time.Duration                                           //空闲连接在连接池中的超时时间,default:90
	KeepAlive             time.Duration                                           //keepalive保活检测定时,default:30
	DnsCacheTime          time.Duration                                           //dns解析缓存时间60*30
	AddrType              AddrType                                                //优先使用的addr 类型
	GetAddrType           func(string) AddrType
	Dns                   string        //dns
	Ja3                   bool          //开启ja3
	Ja3Spec               ja3.Ja3Spec   //指定ja3Spec,使用ja3.CreateSpecWithStr 或者ja3.CreateSpecWithId 生成
	H2Ja3                 bool          //开启h2指纹
	H2Ja3Spec             ja3.H2Ja3Spec //h2指纹

	RedirectNum int   //重定向次数,小于0为禁用,0:不限制
	DisDecode   bool  //关闭自动编码
	DisRead     bool  //关闭默认读取请求体
	DisUnZip    bool  //变比自动解压
	TryNum      int64 //重试次数

	OptionCallBack func(context.Context, *RequestOption) error //请求参数回调,用于对请求参数进行修改。返回error,中断重试请求,返回nil继续
	ResultCallBack func(context.Context, *Response) error      //结果回调,用于对结果进行校验。返回nil,直接返回,返回err的话,如果有errCallBack 走errCallBack,没有继续try
	ErrCallBack    func(context.Context, error) error          //错误回调,返回error,中断重试请求,返回nil继续

	Timeout time.Duration //请求超时时间
	Headers any           //请求头
	Bar     bool          //是否开启bar
}

type Cookies

type Cookies []*http.Cookie

func ReadCookies

func ReadCookies(val any) (Cookies, error)

支持json,map,[]string,http.Header,string

func ReadSetCookies

func ReadSetCookies(val any) (Cookies, error)

func (Cookies) Get

func (obj Cookies) Get(name string) *http.Cookie

获取符合key 条件的cookies

func (Cookies) GetVal

func (obj Cookies) GetVal(name string) string

获取符合key 条件的cookies的值

func (Cookies) GetVals

func (obj Cookies) GetVals(name string) []string

获取符合key 条件的所有cookies的值

func (Cookies) Gets

func (obj Cookies) Gets(name string) Cookies

获取符合key 条件的所有cookies

func (Cookies) String

func (obj Cookies) String() string

返回cookies 的字符串形式

type DialClient

type DialClient struct {
	// contains filtered or unexported fields
}

func NewDail

func NewDail(ctx context.Context, option DialOption) (*DialClient, error)

func (*DialClient) AddProxyTls

func (obj *DialClient) AddProxyTls(ctx context.Context, conn net.Conn, host string) (net.Conn, error)

func (*DialClient) AddTls

func (obj *DialClient) AddTls(ctx context.Context, conn net.Conn, host string, disHttp bool) (tlsConn *tls.Conn, err error)

func (*DialClient) AddrToIp

func (obj *DialClient) AddrToIp(ctx context.Context, addr string) (string, error)

func (*DialClient) DialContext

func (obj *DialClient) DialContext(ctx context.Context, netword string, addr string) (net.Conn, error)

func (*DialClient) DialContextWithProxy

func (obj *DialClient) DialContextWithProxy(ctx context.Context, netword string, scheme string, addr string, host string, proxyUrl *url.URL) (net.Conn, error)

func (*DialClient) Dialer

func (obj *DialClient) Dialer() *net.Dialer

func (*DialClient) DnsDialContext

func (obj *DialClient) DnsDialContext(ctx context.Context, netword string, addr string) (net.Conn, error)

func (*DialClient) GetProxy

func (obj *DialClient) GetProxy(ctx context.Context, href *url.URL) (*url.URL, error)

func (*DialClient) Proxy

func (obj *DialClient) Proxy() *url.URL

func (*DialClient) SetGetProxy

func (obj *DialClient) SetGetProxy(getProxy func(ctx context.Context, url *url.URL) (string, error))

func (*DialClient) SetProxy

func (obj *DialClient) SetProxy(proxy string) error

func (*DialClient) Socks5Proxy

func (obj *DialClient) Socks5Proxy(ctx context.Context, network string, addr string, proxyUrl *url.URL) (conn net.Conn, err error)

type DialOption

type DialOption struct {
	TLSHandshakeTimeout time.Duration
	DnsCacheTime        time.Duration
	KeepAlive           time.Duration
	GetProxy            func(ctx context.Context, url *url.URL) (string, error)
	Proxy               string   //代理
	LocalAddr           string   //使用本地网卡
	AddrType            AddrType //优先使用的地址类型,ipv4,ipv6 ,或自动选项
	GetAddrType         func(string) AddrType
	Ja3                 bool        //是否启用ja3
	Ja3Spec             ja3.Ja3Spec //指定ja3Spec,使用ja3.CreateSpecWithStr 或者ja3.CreateSpecWithId 生成
	ProxyJa3            bool        //代理是否启用ja3
	ProxyJa3Spec        ja3.Ja3Spec //指定代理ja3Spec,使用ja3.CreateSpecWithStr 或者ja3.CreateSpecWithId 生成
	Dns                 string      //dns
}

type Event

type Event struct {
	Data    string
	Event   string
	Id      string
	Retry   int
	Comment string
}

type File

type File struct {
	Key     string //字段的key
	Name    string //文件名
	Content []byte //文件的内容
	Type    string //文件类型
}

构造一个文件

type Jar

type Jar struct {
	// contains filtered or unexported fields
}

func NewJar

func NewJar() *Jar

func (*Jar) ClearCookies

func (obj *Jar) ClearCookies()

func (*Jar) Cookies

func (obj *Jar) Cookies(href string, cookies ...any) (Cookies, error)

type RequestDebug

type RequestDebug struct {
	Url    *url.URL
	Method string
	Header http.Header
	Proto  string
	// contains filtered or unexported fields
}

func (*RequestDebug) Body

func (obj *RequestDebug) Body() (*bytes.Buffer, error)

func (*RequestDebug) Bytes

func (obj *RequestDebug) Bytes() []byte

func (*RequestDebug) String

func (obj *RequestDebug) String() string

type RequestOption

type RequestOption struct {
	Method  string        //method
	Url     *url.URL      //请求的url
	Host    string        //网站的host
	Proxy   string        //代理,支持http,https,socks5协议代理,例如:http://127.0.0.1:7005
	Timeout time.Duration //请求超时时间
	Headers any           //请求头,支持:json,map,header
	Cookies any           // cookies,支持json,map,str,http.Header
	Files   []File        //发送multipart/form-data,文件上传
	Params  any           //url 中的参数,用以拼接url,支持json,map
	Form    any           //发送multipart/form-data,适用于文件上传,支持json,map
	Data    any           //发送application/x-www-form-urlencoded,适用于key,val,支持string,[]bytes,json,map

	Body        io.Reader
	Json        any            //发送application/json,支持:string,[]bytes,json,map
	Text        any            //发送text/xml,支持string,[]bytes,json,map
	ContentType string         //headers 中Content-Type 的值
	Raw         any            //不设置context-type,支持string,[]bytes,json,map
	TempData    map[string]any //临时变量,用于回调存储或自由度更高的用法
	DisCookie   bool           //关闭cookies管理,这个请求不用cookies池
	DisDecode   bool           //关闭自动解码
	Bar         bool           //是否开启bar
	DisProxy    bool           //是否关闭代理,强制关闭代理
	TryNum      int64          //重试次数

	OptionCallBack func(context.Context, *RequestOption) error //请求参数回调,用于对请求参数进行修改。返回error,中断重试请求,返回nil继续
	ResultCallBack func(context.Context, *Response) error      //结果回调,用于对结果进行校验。返回nil,直接返回,返回err的话,如果有errCallBack 走errCallBack,没有继续try
	ErrCallBack    func(context.Context, error) error          //错误回调,返回error,中断重试请求,返回nil继续

	RequestCallBack  func(context.Context, *RequestDebug) error  //request回调,用于定位bug,正常请求不要设置这个函数
	ResponseCallBack func(context.Context, *ResponseDebug) error //response回调,用于定位bug,正常请求不要设置这个函数

	Jar *Jar //自定义临时cookies 管理

	RedirectNum int              //重定向次数,小于零 关闭重定向
	DisRead     bool             //关闭默认读取请求体,不会主动读取body里面的内容,需用你自己读取
	DisUnZip    bool             //关闭自动解压
	WsOption    websocket.Option //websocket option,使用websocket 请求的option
	// contains filtered or unexported fields
}

请求参数选项

type Response

type Response struct {
	// contains filtered or unexported fields
}

func Connect

func Connect(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func Delete

func Delete(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func Get

func Get(preCtx context.Context, href string, options ...RequestOption) (*Response, error)
func Head(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func Options

func Options(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func Patch

func Patch(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func Post

func Post(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func Put

func Put(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func Request

func Request(preCtx context.Context, method string, href string, options ...RequestOption) (*Response, error)

func Trace

func Trace(preCtx context.Context, href string, options ...RequestOption) (*Response, error)

func (*Response) Close

func (obj *Response) Close() error

关闭response ,当disRead 为true 请一定要手动关闭

func (*Response) Content

func (obj *Response) Content() []byte

func (*Response) ContentEncoding

func (obj *Response) ContentEncoding() string

获取headers 的Content-Encoding

func (*Response) ContentLength

func (obj *Response) ContentLength() int64

获取response 的内容长度

func (*Response) ContentType

func (obj *Response) ContentType() string

获取headers 的Content-Type

func (*Response) Cookies

func (obj *Response) Cookies() Cookies

返回这个请求的setCookies

func (*Response) Decode

func (obj *Response) Decode(encoding string)

对内容进行解码

func (*Response) Headers

func (obj *Response) Headers() http.Header

返回response 的请求头

func (*Response) Html

func (obj *Response) Html() *bs4.Client

尝试解析成dom 对象

func (*Response) Json

func (obj *Response) Json(vals ...any) (gjson.Result, error)

尝试将请求解析成gjson, 如果传值将会解析到val中返回的gjson为空struct

func (*Response) Location

func (obj *Response) Location() (*url.URL, error)

返回当前的Location

func (*Response) Map

func (obj *Response) Map() map[string]any

尝试将内容解析成map

func (*Response) Read

func (obj *Response) Read(con []byte) (int, error)

func (*Response) Response

func (obj *Response) Response() *http.Response

返回原始http.Response

func (*Response) SetContent

func (obj *Response) SetContent(val []byte)

返回内容的二进制,也可设置内容

func (*Response) SseClient

func (obj *Response) SseClient() *SseClient

func (*Response) Status

func (obj *Response) Status() string

返回这个请求的状态

func (*Response) StatusCode

func (obj *Response) StatusCode() int

返回这个请求的状态码

func (*Response) Text

func (obj *Response) Text() string

返回内容的字符串形式

func (*Response) Url

func (obj *Response) Url() *url.URL

返回这个请求的url

func (*Response) WebSocket

func (obj *Response) WebSocket() *websocket.Conn

返回websocket 对象,当发送websocket 请求时使用

type ResponseDebug

type ResponseDebug struct {
	Proto  string
	Status string
	Header http.Header
	// contains filtered or unexported fields
}

func (*ResponseDebug) Body

func (obj *ResponseDebug) Body() (*bytes.Buffer, error)

func (*ResponseDebug) Bytes

func (obj *ResponseDebug) Bytes() []byte

func (*ResponseDebug) String

func (obj *ResponseDebug) String() string

type SseClient

type SseClient struct {
	// contains filtered or unexported fields
}

func (*SseClient) Recv

func (obj *SseClient) Recv() (Event, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL