我已经编写了以下代码,将标题字段添加到我的Raven数据库中的文档1中。
我不明白为什么它不能正常工作?我得到的响应主体是以下内容,这不是我期望的。我期望一个成功的响应。
有人能指出我在上面的代码中缺少什么吗?
url := "http://localhost:8083/databases/drone/docs/1"
fmt.Println("URL:>", url)
var jsonStr = []byte(`{"title":"Buy cheese and bread for breakfast."}`)
req, _ := http.NewRequest("PATCH", url, bytes.NewBuffer(jsonStr))
req.Header.Set("X-Custom-Header", "myvalue")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))
我不明白为什么它不能正常工作?我得到的响应主体是以下内容,这不是我期望的。我期望一个成功的响应。
<html>
<body>
<h1>Could not figure out what to do</h1>
<p>Your request didn't match anything that Raven knows to do, sorry...</p>
</body>
有人能指出我在上面的代码中缺少什么吗?
curl -X POST -d '{"title": "Buy cheese and bread for breakfast."}' -H 'X-Custom-Header: myvalue' -H 'Content-Type: application/json' http://localhost:8083/databases/drone/docs/1
可以正常工作,是吗? - sberry