浏览代码

general post json

master
Patrick Peng Sun 8 年前
父节点
当前提交
bc71af3b59
共有 1 个文件被更改,包括 16 次插入0 次删除
  1. +16
    -0
      upload.go

+ 16
- 0
upload.go 查看文件

@@ -52,3 +52,19 @@ func postFileForm(filename string, targetURL string, formFieldName string) (strJ
fmt.Println(string(strJSON))
return strJSON, nil
}

func postJSON(jsonB []byte, targetURL string) (resp string, err error) {
req, err := http.NewRequest("POST", targetURL, bytes.NewBuffer(jsonB))
if err != nil {
return
}
client := &http.Client{}
r, err := client.Do(req)
if err != nil {
return
}
defer r.Body.Close()
b, _ := ioutil.ReadAll(r.Body)
resp = string(b)
return
}

正在加载...
取消
保存