Browse Source

增加发送json方法

master v0.2.0
guzeng 3 years ago
parent
commit
dcd280563a
1 changed files with 28 additions and 0 deletions
  1. +28
    -0
      url.go

+ 28
- 0
url.go View File

@ -4,6 +4,7 @@
package network package network
import ( import (
"bytes"
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
"errors" "errors"
@ -45,6 +46,33 @@ func FnPost(url, param string) ([]byte, error) {
return body, nil return body, nil
} }
/**
* post 请求
*/
func PostJson(url string, param []byte) ([]byte, error) {
httpClient := &http.Client{}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(param))
if err != nil {
return []byte(""), err
}
req.Header.Set("Content-Type", "application/json")
resp, err := httpClient.Do(req)
if err != nil {
return []byte(""), err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return []byte(""), err
}
return body, nil
}
/** /**
* 取本地IP * 取本地IP
*/ */


Loading…
Cancel
Save