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"?>
<SubscribeEvent xmlns="http://www.isapi.org/ver20/XMLSchema" version="2.0">
<heartbeat min="1" max="30"/>
<channelMode>all</channelMode>
<eventMode>all</eventMode>
<EventList>
<Event>
<type>QRCodeEvent</type>
</Event>
</EventList>
</SubscribeEvent>"""
response = requests.post(request_url,postdata, auth=auth, stream=True)
print(response.headers)
while True :
print(response.raw.read(1000))