requests

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 13 Imported by: 0

README

介绍

一个方便好用的 Go Requests

使用

GET

resp := requests.Get("https://www.baidu.com/")

POST

requests.Post("https://example.com", params.BodyString("user=xxx&pass=xxx"))

requests.Post("https://example.com", params.BodyMap2String{
    "user": "xxx",
    "pass": "xxx",
})

requests.Post("https://example.com", params.BodyJsonString("{\"user\":\"xxx\",\"pass\":\"xxx\"}"))

requests.Post("https://example.com", params.BodyMap2Json{
    "user": "xxx",
    "pass": "xxx",
})

自动保存 Cookie

session := requests.Session()

get := session.Get(method.GET, params.Url("http://www.baidu.com/"), headers)
if get != nil {
    fmt.Println(get.Response.Status)
    fmt.Println(get.Response.Cookies())
}

get1 := session.Post("http://www.baidu.com/", headers, params.BodyMap2Json{
    "user": "xxx",
    "pass": "xxx",
})
if get1 != nil {
    fmt.Println(get1.Response.Status)
    fmt.Println(get1.Response.Cookies())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Requests

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

func NewRequests

func NewRequests(client *http.Client) *Requests

func Session

func Session() *Requests

func (*Requests) Get

func (r *Requests) Get(url string, args ...interface{}) *Response

func (*Requests) Post

func (r *Requests) Post(url string, args ...interface{}) *Response

func (*Requests) Request

func (r *Requests) Request(m method.Method, url string, args ...any) *Response

func (*Requests) SetProxy

func (r *Requests) SetProxy(proxy string) error

type Response

type Response struct {
	Response *http.Response
	Text     string
}

func Get

func Get(url string, args ...interface{}) *Response

func Post

func Post(url string, args ...interface{}) *Response

func Request

func Request(method method.Method, url string, args ...interface{}) *Response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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