You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
737 B
34 lines
737 B
package generalmethod
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"net/http"
|
|
)
|
|
|
|
// Get请求
|
|
func CurlGet(getUrl string) []byte {
|
|
client := &http.Client{}
|
|
reqest, err := http.NewRequest("GET", getUrl, nil)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
response, _ := client.Do(reqest)
|
|
defer response.Body.Close()
|
|
body, err := ioutil.ReadAll(response.Body)
|
|
return body
|
|
}
|
|
|
|
// Post请求 json
|
|
func CurlPostJosn(postUrl string, jsonData []byte) []byte {
|
|
req, err := http.NewRequest("POST", postUrl, bytes.NewBuffer(jsonData))
|
|
req.Header.Set("Content-Type", "application/json;charset=utf-8")
|
|
client := &http.Client{}
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer resp.Body.Close()
|
|
body, _ := ioutil.ReadAll(resp.Body)
|
|
return body
|
|
}
|
|
|