httputil

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeJSON = "application/json"
	ContentTypeForm = "application/x-www-form-urlencoded"
)

Variables

This section is empty.

Functions

func DealResponse

func DealResponse(resp *http.Response) ([]byte, error)

DealResponse 读取并关闭响应体

func Get

func Get(ctx context.Context, url string, params map[string]interface{}, options ...map[string]interface{}) (*http.Response, error)

Get 执行 GET 请求

func NewFormPostRequest

func NewFormPostRequest(urlStr string, params map[string]interface{}, headers ...map[string]string) (*http.Request, error)

NewFormPostRequest 创建一个新的 POST 请求,使用表单数据

func NewGetRequest

func NewGetRequest(url string, params map[string]interface{}, headers ...map[string]string) (*http.Request, error)

NewGetRequest 创建一个新的 GET 请求

func NewJSONPostRequest

func NewJSONPostRequest(url string, params map[string]interface{}, headers ...map[string]string) (*http.Request, error)

NewJSONPostRequest 创建一个新的 POST 请求,使用 JSON 数据

func Post

func Post(ctx context.Context, url string, params map[string]interface{}, options ...map[string]interface{}) (*http.Response, error)

Post 执行 POST 请求,使用表单数据

func PostJSON

func PostJSON(ctx context.Context, url string, params map[string]interface{}, options ...map[string]interface{}) (*http.Response, error)

PostJSON 执行 POST 请求,使用 JSON 数据

func Request

func Request(ctx context.Context, method, url string, params map[string]interface{}, options ...map[string]interface{}) (*http.Response, error)

Request 执行指定方法的 HTTP 请求

Types

type Client

type Client interface {
	Do(ctx context.Context, req *http.Request) (*http.Response, error)
}

Client 定义了 HTTP 客户端的接口

func NewClient

func NewClient(timeout time.Duration) Client

NewClient 创建一个新的 Client 实例

Jump to

Keyboard shortcuts

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