doukun1450 2016-09-30 18:21
浏览 78

golang在发布时接受压缩数据

I am trying to send some data that is gzipped on a post to a golang server and use it gunzipped in the post. Basically, i do the following input

curl -X POST -H "Content-Encoding: gzip" -d @helloworld.gz http://myapp/

on the server side

func PostEndpoint(w http.ResponseWriter, req *http.Request) {
   gunzip, err := gzip.NewReader(req.Body)
   if err != nil {
      log.Println("error unzip: ",err)
   }
   body , _ := ioutil.ReadAll(gunzip)
}

I keep getting a EOF error. I tried to print the raw bytes with ioutil.ReadAll(req.Body) and it is not really the full data i sent in from curl.

Is there something that needs to be configured to mux? right now i create it as

router := mux.NewRouter()
router.HandleFunc("/", GetEndpoint).Methods("GET")
router.HandleFunc("/", PostEndpoint).Methods("POST")
log.Fatal(http.ListenAndServe(":80", router))
  • 写回答

1条回答 默认 最新

  • dtp19819 2016-09-30 19:08
    关注

    had to use --binary-data on curl instead of --data

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line