curl

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: MIT Imports: 13 Imported by: 1

README

请求方式代号

package http

// http.MethodPost

const (
	MethodGet     = "GET"
	MethodHead    = "HEAD"
	MethodPost    = "POST"
	MethodPut     = "PUT"
	MethodPatch   = "PATCH" // RFC 5789
	MethodDelete  = "DELETE"
	MethodConnect = "CONNECT"
	MethodOptions = "OPTIONS"
	MethodTrace   = "TRACE"
)

Documentation

Index

Constants

View Source
const (
	CONTENT_TYPE_JSON      = "application/json"
	CONTENT_TYPE_FORM      = "application/x-www-form-urlencoded"
	CONTENT_TYPE_OCTET     = "application/octet-stream"
	CONTENT_TYPE_MULTIPART = "multipart/form-data"
	CONTENT_TYPE_XML       = "application/xml"
	CONTENT_TYPE_TEXTHTML  = "text/html"
	CONTENT_TYPE_TEXTXML   = "text/xml"
)

Variables

This section is empty.

Functions

func AppendParamToUrl added in v1.0.1

func AppendParamToUrl(url, param string) string

向url中追加参数

func Base64Decode

func Base64Decode(str string) (string, error)

func Base64DecodeV2 added in v1.0.4

func Base64DecodeV2(b []byte) ([]byte, error)

func Base64Encode

func Base64Encode(str string) string

func Base64EncodeV2 added in v1.0.4

func Base64EncodeV2(b []byte) []byte

func HttpGet

func HttpGet(urlStr string) (string, error)

HttpGet 发起get请求

func HttpPost

func HttpPost(urlStr string, param string) (string, error)

HttpPost 发起表单post请求 param := "name=李四&age=19"

func HttpPostForm

func HttpPostForm(urlStr string, param url.Values) (string, error)

HttpPostForm param := url.Values{"参数名1": {"值1"}, "参数名2": {"值1","值N"}}

func HttpPostJson

func HttpPostJson(urlStr string, param string) (string, error)

func HttpPostXml added in v1.0.4

func HttpPostXml(urlStr string, xmlStr string) (string, error)

func IsBlank added in v1.0.1

func IsBlank(str string) bool

是否空串 或者 全是 空格

func ParamValueToString

func ParamValueToString(i interface{}) string

func ParseUrlAndAppendParam added in v1.0.2

func ParseUrlAndAppendParam(reqUrl string, queryParams map[string][]string) (string, error)

分析url并追加参数

func ReadBodyContent added in v1.0.2

func ReadBodyContent(httpResp *http.Response) (string, error)

func ReadBodyContent2Byte added in v1.0.2

func ReadBodyContent2Byte(httpResp *http.Response) ([]byte, error)

func TrimPath

func TrimPath(path string, pos int) string

func UnMarshalResponse added in v1.0.2

func UnMarshalResponse(httpResp *http.Response, resp interface{}) error

func UrlDecode

func UrlDecode(str string) (string, error)

func UrlEncode

func UrlEncode(str string) string

Types

type HttpRequest

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

请求结构体

func NewHttpRequest

func NewHttpRequest() *HttpRequest

创建一个Request对象

func (*HttpRequest) AddHeader

func (this *HttpRequest) AddHeader(header, val string) *HttpRequest

func (*HttpRequest) Delete

func (this *HttpRequest) Delete() (*HttpResponse, error)

发起Delete请求

func (*HttpRequest) Get

func (this *HttpRequest) Get() (*HttpResponse, error)

发起get请求

func (*HttpRequest) GetCookies

func (this *HttpRequest) GetCookies() map[string]string

func (HttpRequest) GetHeaders

func (this HttpRequest) GetHeaders() map[string]string

func (HttpRequest) GetMethod

func (this HttpRequest) GetMethod() string

func (HttpRequest) GetPostData

func (this HttpRequest) GetPostData() map[string]interface{}

func (HttpRequest) GetQueries

func (this HttpRequest) GetQueries() map[string]string

func (HttpRequest) GetRawPostData

func (this HttpRequest) GetRawPostData() string

func (*HttpRequest) GetTimeout

func (this *HttpRequest) GetTimeout() time.Duration

func (HttpRequest) GetUrl

func (this HttpRequest) GetUrl() string

func (*HttpRequest) Patch

func (this *HttpRequest) Patch() (*HttpResponse, error)

发起PATCH请求

func (*HttpRequest) Post

func (this *HttpRequest) Post() (*HttpResponse, error)

发起post请求

func (*HttpRequest) Put

func (this *HttpRequest) Put() (*HttpResponse, error)

发起Put请求

func (*HttpRequest) Request

func (this *HttpRequest) Request() (*HttpResponse, error)

func (*HttpRequest) SetCookies

func (this *HttpRequest) SetCookies(cookies map[string]string) *HttpRequest

设置请求cookies

func (*HttpRequest) SetDialTimeOut

func (this *HttpRequest) SetDialTimeOut(TimeOutSecond int64) *HttpRequest

func (*HttpRequest) SetHeaders

func (this *HttpRequest) SetHeaders(headers map[string]string) *HttpRequest

设置请求头

func (*HttpRequest) SetMethod

func (this *HttpRequest) SetMethod(method string) *HttpRequest

设置请求方法,返回Request结构体对象用于链式调用

func (*HttpRequest) SetPostData

func (this *HttpRequest) SetPostData(postData map[string]interface{}) *HttpRequest

设置post请求的提交数据

func (*HttpRequest) SetPostType

func (this *HttpRequest) SetPostType(typeStr string) *HttpRequest

func (*HttpRequest) SetQueries

func (this *HttpRequest) SetQueries(queries map[string]string) *HttpRequest

设置url查询参数

func (*HttpRequest) SetRawPostData

func (this *HttpRequest) SetRawPostData(rawPostData string) *HttpRequest

func (*HttpRequest) SetResponseTimeOut

func (this *HttpRequest) SetResponseTimeOut(TimeOutSecond int64) *HttpRequest

func (*HttpRequest) SetTimeout

func (this *HttpRequest) SetTimeout(TimeOutSecond int64) *HttpRequest

func (*HttpRequest) SetUrl

func (this *HttpRequest) SetUrl(url string) *HttpRequest

设置请求地址

type HttpResponse

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

func NewHttpResponse

func NewHttpResponse() *HttpResponse

func (HttpResponse) GetBody

func (this HttpResponse) GetBody() string

响应内容

func (HttpResponse) GetHeaders

func (this HttpResponse) GetHeaders() map[string]string

func (*HttpResponse) GetRaw

func (this *HttpResponse) GetRaw() *http.Response

func (*HttpResponse) IsOk

func (this *HttpResponse) IsOk() bool

func (*HttpResponse) SetRaw

func (this *HttpResponse) SetRaw(r *http.Response) *HttpResponse

type Params

type Params map[string]interface{}

自定义类型

func NewParams

func NewParams() Params

func (Params) Del

func (p Params) Del(key string)

删除

func (Params) GetParam

func (p Params) GetParam(key string, defaultVal interface{}) interface{}

获取

func (Params) Set

func (p Params) Set(key string, value interface{})

为类型添加方法,设置参数值

func (Params) SetParams

func (p Params) SetParams(params Params)

批量设置参数

func (Params) ToQueryString

func (p Params) ToQueryString() string

返回结果示例:empty=&is_supper=true&price=100.25&userid=123&username=tom

Jump to

Keyboard shortcuts

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