Explorar el Código

general post json

master
Patrick Peng Sun hace 8 años
padre
commit
bc71af3b59
Se han modificado 1 ficheros con 16 adiciones y 0 borrados
  1. +16
    -0
      upload.go

+ 16
- 0
upload.go Ver fichero

@@ -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
}

Cargando…
Cancelar
Guardar