client

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	FORM_MULTIPART   = "multipart/form-data"
	FORM_ENCODED     = "application/x-www-form-urlencoded"
	APPLICATION_JSON = "application/json"

	CONTENT_TYPE = "Content-Type"
)

Variables

This section is empty.

Functions

func Get

func Get(client *http.Client, reqUrl string, reqParams map[string]string, headers map[string]string) (*http.Response, error)

Get request to target url http server

func PostFile

func PostFile(client *http.Client, reqUrl string, reqParams map[string]string, files []FileUploadInfo, headers map[string]string) (*http.Response, error)

PostFile to post files to http server

Example
package main

import (
	"fmt"
	"io/ioutil"
	"net/http"

	"github.com/jhunters/goassist/web/client"
)

func main() {

	files := []client.FileUploadInfo{
		{Name: "file", Filepath: `../../testresources/hello.txt`, FileName: "hello_upload.txt"},
	}

	var httpClient = &http.Client{}
	response, err := client.PostFile(httpClient, "http://localhost:8080/FileTest", map[string]string{}, files, map[string]string{})
	if err != nil {
		fmt.Println(err)
		return
	}

	if response != nil {
		content, _ := ioutil.ReadAll(response.Body)
		defer response.Body.Close()
		fmt.Println(string(content))
	}

}
Output:

func PostForm

func PostForm(client *http.Client, reqUrl string, reqParams map[string]string, headers map[string]string) (*http.Response, error)

PostForm to post form field and value to http server

func PostJson

func PostJson(client *http.Client, reqUrl string, reqParams map[string]string, headers map[string]string) (*http.Response, error)

PostJson to post json format value to http server

Types

type FileUploadInfo

type FileUploadInfo struct {
	// 表单名称
	Name string
	// 文件全路径
	Filepath string
	// 文件名
	FileName string
}

FileUploadInfo upload file info struct

Jump to

Keyboard shortcuts

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