為了在 NoSQL 存儲中設置 K/V,我需要在 go 中創建一個等效于以下curl命令的命令:curl -H "Content-Type: text/xml" --data '[...]' http://localhost:8000/test/testrow/test:testcolumn我正在嘗試為此目的使用以下代碼行中的某些內容,盡管我無法找到如何將二進制數據 []byte(value) 設置為 POST 有效負載。func setColumn(table string, key string, col string, value string) {url := "http://localhost:8123/" + table + "/" + key + "/" + colreq, err := http.NewRequest("POST", url, nil)req.Header.Set("Content-Type", "application/octet-stream")data = []byte(value)client := &http.Client{}resp, err := client.Do(req)if err != nil { // handle error}defer resp.Body.Close()body, err := ioutil.ReadAll(resp.Body)fmt.Println(string(body))}那么,如何在 POST 請求中映射數據負載?歡迎任何指標。
- 1 回答
- 0 關注
- 200 瀏覽
添加回答
舉報
0/150
提交
取消