【发布时间】:2016-01-19 04:25:45
【问题描述】:
//read data from a file config.json
//the contents of config.json is
//{"key1":"...Z-DAaFpGT0t...","key2":"..."}
client := &http.Client{}
dat, err := ioutil.ReadFile("/config.json")
req, err := http.NewRequest("PUT", url, bytes.NewBuffer(dat))
resp, err := client.Do(req)
然后我会从服务器收到错误消息“400 Bad Request”、““invalid character 'ï' looking for beginning of value”。
数据似乎没有正确解码。
虽然下面的代码有效
client := &http.Client{}
//dat, err := ioutil.ReadFile("/config.json")
var dat = []byte(`{"key1":"...Z-DAaFpGT0t...","key2":"..."}`)
req, err := http.NewRequest("PUT", url, bytes.NewBuffer(dat))
resp, err := client.Do(req)
【问题讨论】:
-
你在检查那些错误吗?
-
可以分享/config.json的内容吗?
标签: http go filereader