httpclient

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: MulanPSL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const HTTP_CONTENT_TYPE_JSON string = "application/json"
View Source
const HTTP_TIMEOUT_DEFAULT time.Duration = time.Second * 10

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpClient

type HttpClient struct {
	Proxy          string // 代理地址, 如果有配置, 使用此地址做代理
	NicIp          string // 网卡IP, 如果有配置, 便宜此网卡做出口
	Timeout        time.Duration
	Method         string         // 访问方式, 默认GET
	RequestHandler RequestHandler // 请求处理器, 可以对请求进行一些初始化操作, 比如设置头部信息等
}

func NewHttpClient

func NewHttpClient() *HttpClient

func (*HttpClient) Get

func (_t *HttpClient) Get(targetUrl string) (responseBody string, err error)

func (*HttpClient) GetHttpCode

func (_t *HttpClient) GetHttpCode(targetUrl string) (httpCode int, err error)

func (HttpClient) GetTransport

func (_t HttpClient) GetTransport() *http.Transport

func (*HttpClient) GetWithParams

func (_t *HttpClient) GetWithParams(targetUrl string, params url.Values) (string, error)

func (*HttpClient) Post

func (_t *HttpClient) Post(targetUrl string, contentType string, body []byte) (responseBody string, err error)

func (HttpClient) Request

func (_t HttpClient) Request(
	targetUrl string,
	contentType string,
	body []byte) (responseBody string, httpCode int, err error)

func (*HttpClient) SetNicIp

func (_t *HttpClient) SetNicIp(nicIp string) *HttpClient

设置出口网卡IP

func (*HttpClient) SetProxy

func (_t *HttpClient) SetProxy(proxy string) *HttpClient

设置代理地址

func (*HttpClient) SetRequestHandler

func (_t *HttpClient) SetRequestHandler(handler RequestHandler) *HttpClient

设置请求处理器, 可以对请求进行一些初始化操作, 比如设置头部信息等

func (*HttpClient) SetTimeout

func (_t *HttpClient) SetTimeout(timeout time.Duration) *HttpClient

设置请求超时

type RequestHandler

type RequestHandler func(*http.Request)

Jump to

Keyboard shortcuts

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