client := &http.Client{ Transport: tr, }
url := host + "/ISAPI/Event/notification/subscribeEvent"
bodyBuffer := bytes.NewBuffer([]byte(``))
request, err := http.NewRequest("POST", url, bodyBuffer)
if err != nil {
return err
}
request.Header.Set("Connection", "keep-alive")
request.Close = false
resp, err := client.Do(request)
if err != nil {
fmt.Println("client do err")
return err
}
buf := make([]byte, 4096) // any non zero value will do, try '1'.
for {
n, err := resp.Body.Read(buf)
if n == 0 && err != nil { // simplified
break
}
fmt.Printf("%s", buf[:n]) // no need to convert to string here
}
在client.Do(request) 后返回错误:net/http: HTTP/1.x transport connection broken: malformed MIME header: missing colon: "--MIME_boundary" --- FAIL: TestHttp2 (0.03s)
url是一个长连接 post请求后会不段有返回数据,请问是否有人知道怎么处理
此url用python测试是没问题的,不知道go需要处理处理
python:
import requests
request_url = 'http://192.168.1.110/ISAPI/Event/notification/subscribeEvent'
auth = requests.auth.HTTPDigestAuth('admin', 'linkbee123')
postdata = """<?xml version="1.0" encoding="UTF-8"?>
有疑问加站长微信联系(非本文作者)

看看这个,是否有帮助? Go http client 连接池不复用的问题 http://www.1024ask.com/go/232512
11
无关
什么版本的?搜出来都是10以前的问题
go version go1.18.2 darwin/amd64
post请求后会不段有返回数据,请问是否有人知道怎么处理
? http1.1以前是请求-响应模型,一次请求对应一个响应。自带 http 里面支持长连接,支持连接池,连接过多会一直保持活性连接
你在 test http/2, 但是用的是 http/1.1