http

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

HTTP

一、GET请求
package main

import "github.com/daimayun/go/http"

func main() {
    http.Get("https://www.baidu.com")
}
二、POST请求
1、POST JSON
package main

import (
    "encoding/json"
    "fmt"
    "github.com/daimayun/go/http"
    "strings"
)

func main() {
    type requestBody struct {
        Code string `json:"code"`
    }
    reqParam, err := json.Marshal(struct {
        Code string `json:"code"`
    }{Code: "xxx"})
    if err != nil {
        return
    }
    url := "https://www.baidu.com"
    b, err := http.PostJson(url, strings.NewReader(string(reqParam)))
    fmt.Print(string(b))
}
2、POST FORM
package main

import (
    "fmt"
    "github.com/daimayun/go/http"
    "net/url"
    "strings"
)

func main() {
    b, err := http.PostForm("https://www.baidu.com", url.Values{"captcha_id": []string{"DkgMECFm9mzXbdFCZnKx"}, "captcha_value": []string{"5027"}})
    if err != nil {
        return
    }
    fmt.Println(string(b))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(url string, headers ...map[string]string) (b []byte, err error)

Get get请求

func PostForm

func PostForm(url string, data url.Values) (b []byte, err error)

PostForm post_form

func PostJson

func PostJson(url string, jsonStrReader io.Reader, headers ...map[string]string) (b []byte, err error)

PostJson post_json

func Request added in v0.11.10

func Request(method, url string, jsonStrReader io.Reader, headers ...map[string]string) (b []byte, err error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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