1 回答

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個贊
這是使用多部分請求的示例。我根據(jù)處理 JSON 文檔的一段代碼修改了它,因此其中可能存在一些錯誤,但它應(yīng)該給您一個想法:
body := bytes.Buffer{}
writer := multipart.NewWriter(&body)
hdr := textproto.MIMEHeader{}
hdr.Set("Content-Type", "text/plain")
part, _ := writer.CreatePart(hdr)
part.Write(data1)
hdr = textproto.MIMEHeader{}
hdr.Set("Content-Type", <image type>)
part, _ = writer.CreatePart(hdr)
part.Write(imageData)
... // Add more parts if you need to
writer.Close()
request, _ := http.NewRequest(http.MethodPost, url, &body)
request.Header.Set("Content-Type", fmt.Sprintf("multipart/mixed;boundary=%s", writer.Boundary()))
hcli := http.Client{}
rsp, err := hcli.Do(request)
- 1 回答
- 0 關(guān)注
- 125 瀏覽
添加回答
舉報