request

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

Package request 提供Tigo框架自带的http client功能,此包包含发送http请求的方法。

Package request request 包是Tigo框架的http客户端包,主要用来向服务端发送http请求,该包主要用来做http接口调用,目前尚不支持通过http接口上传文件,但是相 关代码可以二次封装,开发者可以自行拓展接口,实现文件上传。 --------------------------------------------------------------------------------------------------------------------- 发送基础的http请求,代码示例如下:

Basic Example:

url := "https://www.github.com"
response, err := request.Get(url)
if err != nil {
	panic(err.Error())
}
print(response.ToContentStr())

--------------------------------------------------------------------------------------------------------------------- 如果要post请求,发送一个json到服务端,可以参考如下示例:

Basic Example:

url := "https://your.server.address:port/request-url"
headers := map[string]string{
	"Content-Type": "application/json",
}
param := map[string]interface{}{
	"param": "value",
}
response, err := request.Post(url, param, headers)
print(response.ToContentStr())

--------------------------------------------------------------------------------------------------------------------- `request.Response`继承了`http.Response`,封装了成员变量Content,主要是http response报文的报文体的内容,方便开发者查看报文以及做一 些定制化开发。

Index

Constants

View Source
const (
	GET     string = "GET"
	POST    string = "POST"
	PUT     string = "PUT"
	PATCH   string = "PATCH"
	HEAD    string = "HEAD"
	OPTIONS string = "OPTIONS"
	DELETE  string = "DELETE"
)

Variables

This section is empty.

Functions

func Map2Xml added in v1.0.8

func Map2Xml(inputMap map[string]interface{}, versionAndEncode ...string) (xml string)

Map2Xml map转xml

  • versionAndEncode 版本号和编码,[]string{version, encode}

Types

type HttpClient

type HttpClient struct {
	*http.Client
}

HttpClient 是自定义HTTPClient

type Response

type Response struct {
	*http.Response
	Content []byte
}

Response 自定义Http的Response

func Delete

func Delete(requestUrl string, headers ...map[string]string) (*Response, error)

Delete 向指定url发送delete请求

func Get

func Get(requestUrl string, headers ...map[string]string) (*Response, error)

Get 向指定url发送get请求

func Head(requestUrl string, headers ...map[string]string) (*Response, error)

Head 向指定url发送head请求

func MakeRequest added in v1.0.8

func MakeRequest(method string, requestUrl string, bodyReader io.Reader, headers ...map[string]string) (*Response, error)

MakeRequest 发送指定的Request请求

  • method 请求方式
  • requestUrl 请求地址
  • bodyReader 请求体
  • headers 报文头,缺省

func Options

func Options(requestUrl string, headers ...map[string]string) (*Response, error)

Options 向指定url发送options请求

func Patch

func Patch(requestUrl string, postParams map[string]interface{}, headers ...map[string]string) (*Response, error)

Patch 向指定url发送patch请求

func Post

func Post(requestUrl string, postParams map[string]interface{}, headers ...map[string]string) (*Response, error)

Post 向指定url发送post请求

func Put

func Put(requestUrl string, postParams map[string]interface{}, headers ...map[string]string) (*Response, error)

Put 向指定url发送put请求

func Request

func Request(method string, requestUrl string, postParams map[string]interface{}, headers ...map[string]string) (*Response, error)

Request 发送指定的Request请求

  • method 请求方式
  • requestUrl 请求地址
  • postParam 请求参数,k-v格式
  • headers 报文头,缺省

func (*Response) ToContentStr

func (response *Response) ToContentStr() string

ToContentStr 将Response实例的Content转换为字符串

Jump to

Keyboard shortcuts

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