httputil

package
v0.0.0-...-2c87074 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Unlicense Imports: 6 Imported by: 3

Documentation

Overview

Package httputil implements some http utility functions.

Index

Constants

This section is empty.

Variables

View Source
var InsecureClient = &http.Client{
	Transport: &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	},
}

InsecureClient is a http client which allows https connections with invalid certificates.

Functions

func Get

func Get(rawURL string) (buf []byte, err error)

Get issues a GET to the specified URL and returns the raw response.

func GetDoc

func GetDoc(rawURL string) (doc *html.Node, err error)

GetDoc issues a GET request, parses it and returns an HTML node.

func GetString

func GetString(rawURL string) (s string, err error)

GetString issues a GET to the specified URL and returns the response as a string.

func Post

func Post(rawURL, bodyType, data string) (buf []byte, err error)

Post issues a POST to the specified URL.

func PostString

func PostString(rawURL, bodyType, data string) (s string, err error)

PostString issues a POST to the specified URL and returns the response as a string.

func SetClient

func SetClient(c *http.Client)

SetClient sets the default http client used by httputil requests.

Types

type Session

type Session struct {
	// Cookies used for each session request.
	Cookies []*http.Cookie
	// The User-Agent of each session request. The default Go http User-Agent is
	// used if UserAgent is empty.
	UserAgent string
}

A Session contains the cookies and User-Agent for a series of requests.

func (*Session) Get

func (sess *Session) Get(rawURL string) (buf []byte, err error)

Get issues a GET to the specified URL and returns the raw response. The request uses the session's cookies and User-Agent.

func (*Session) GetString

func (sess *Session) GetString(rawURL string) (s string, err error)

GetString issues a GET to the specified URL and returns the response as a string. The request uses the session's cookies and User-Agent.

func (*Session) Post

func (sess *Session) Post(rawURL, bodyType, data string) (buf []byte, err error)

Post issues a POST to the specified URL. The request uses the session's cookies and User-Agent.

func (*Session) PostString

func (sess *Session) PostString(rawURL, bodyType, data string) (s string, err error)

PostString issues a POST to the specified URL and returns the response as a string. The request uses the session's cookies and User-Agent.

Jump to

Keyboard shortcuts

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