httpClientKit

package
v3.0.97 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTimeout 发送请求的默认超时时间.
	DefaultTimeout = time.Second * 10
)

Variables

View Source
var DefaultHttpClient *http.Client = NewHttpClient(time.Second*3, true)

DefaultHttpClient 默认的 *http.Client 实例

Functions

func Get

func Get(url string, options ...Option) (int, []byte, error)

Get Deprecated: Use reqKit instead.

func GetForResponse

func GetForResponse(url string, options ...Option) (*http.Response, error)

GetForResponse Deprecated: Use reqKit instead.

!!!: 第2个返回值 == nil 的情况下,需要手动调用 resp.Body.Close() 来手动关闭 第1个返回值.

func IsTimeoutError

func IsTimeoutError(err error) (flag bool)

IsTimeoutError 是否是请求超时错误?

func IsValidStatusCode added in v3.0.94

func IsValidStatusCode(code int) bool

IsValidStatusCode 响应的http状态码 是否有效?

PS: (1) 判断参考了jQuery; (2) 正常情况下,响应的http状态码有效的情况下,才会去读取响应的body.

func NewHttpClient added in v3.0.67

func NewHttpClient(timeout time.Duration, insecureSkipVerify bool) *http.Client

func Post

func Post(url string, options ...Option) (int, []byte, error)

Post Deprecated: Use reqKit instead.

func PostForResponse

func PostForResponse(url string, options ...Option) (*http.Response, error)

PostForResponse Deprecated: Use reqKit instead.

!!!: 第2个返回值 == nil 的情况下,需要手动调用 resp.Body.Close() 来手动关闭 第1个返回值.

func Upload

func Upload(url string, fileParams map[string]string, options ...Option) (int, []byte, error)

Upload Deprecated: Use reqKit instead.

func UploadForResponse

func UploadForResponse(url string, fileParams map[string]string, options ...Option) (*http.Response, error)

UploadForResponse Deprecated: Use reqKit instead.

@param fileParams (1)可以为nil或空;

(2)key: 键, value: 要上传文件的路径.

@return !!!: 第一个返回值如果不为nil的话,一般来说需要手动调用 "resp.Body.Close()"

Types

type Option

type Option func(opts *options)

func WithPostParams

func WithPostParams(postParams map[string][]string) Option

WithPostParams

适用于: POST

func WithQueryParams

func WithQueryParams(queryParams map[string][]string) Option

WithQueryParams

适用于: GET、POST

func WithSafe

func WithSafe(safe bool) Option

WithSafe

适用于: GET、POST

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout

适用于: GET、POST

Jump to

Keyboard shortcuts

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