0

for example the curl code:

curl "http://example.com" --data-binary $'abc\r\ndef' --compressed

how to translate it to Go code?

What I have try is:

body := []byte("abc\r\ndef")
req, _ := http.NewRequest("POST", "http://example.com", bytes.NewBuffer(body))
resp, _ := http.DefaultClient.Do(req)
oohcode
  • 431
  • 2
  • 6
  • Why do you think that what you've tried is not already what you are looking for? For me it does exactly the same as the curl cmdline you show: add the given payload without additional processing and also request a compressed response. – Steffen Ullrich Jul 08 '18 at 16:53
  • @SteffenUllrich The missing bits are `--compressed` – dolmen Jul 09 '18 at 18:27
  • @dolmen: to cite myself: *"... and also request a compressed response"*. So, nothing is missing since this is exactly what `--compressed` does. – Steffen Ullrich Jul 09 '18 at 18:39
  • I have solved this problem by this tool https://github.com/two/curl-to-go, fork from https://github.com/mholt/curl-to-go – oohcode Jul 21 '18 at 10:34

0 Answers0