requests

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultUa = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)" +
	" Chrome/76.0.3809.132 Safari/537.36 C845D9D38B3A68F4F74057DB542AD252 tx/2.0"

Variables

View Source
var ContentTypes = map[string]string{
	"json":      "application/json",
	"xml":       "application/xml",
	"soap":      "application/soap+xml",
	"multipart": "multipart/form-data",
	"form":      "application/x-www-form-urlencoded; charset=utf-8",
}

Functions

func UrlParse

func UrlParse(sourceUrl string) (*url.URL, error)

UrlParse 调用url.Parse,增加了对%的处理

Types

type ReqInfo

type ReqInfo struct {
	Verb    string
	Url     string
	Headers map[string]string
	Body    []byte
}

ReqInfo 是一个HTTP请求元素的封装,可以快速进行简单的http请求

func (*ReqInfo) Clone

func (r *ReqInfo) Clone() *ReqInfo

func (*ReqInfo) Request

func (r *ReqInfo) Request() (*Response, error)

Request reqInfo的快速调用

func (*ReqInfo) RequestWithOptions

func (r *ReqInfo) RequestWithOptions(options *ReqOptions) (*Response, error)

func (*ReqInfo) SetHeader

func (r *ReqInfo) SetHeader(name, value string)

type ReqOptions

type ReqOptions struct {
	Timeout       int    // in seconds
	Retry         int    // 0为默认值,-1 代表关闭不retry
	VerifySSL     bool   // default false
	AllowRedirect bool   // default false
	Proxy         string // proxy settings, support http/https proxy only, e.g. http://127.0.0.1:8080
}

type Response

type Response struct {
	http.Response
	// raw text Response
	Text string
}

自定义一些函数

func Get

func Get(url string, headers map[string]string, options *ReqOptions) (*Response, error)

Get GET请求

func NewResponse

func NewResponse(r *http.Response) *Response

func Request

func Request(verb string, url string, headers map[string]string, body []byte, options *ReqOptions) (*Response, error)

Request 自定义请求类型

Jump to

Keyboard shortcuts

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