关于http client长连接请求的问题

dzjzmj · · 3197 次点击 · 开始浏览    置顶
这是一个创建于 的主题,其中的信息可能已经有所发展或是发生改变。

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))

有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

3197 次点击  
加入收藏 微博
8 回复  |  直到 2022-11-21 14:26:43
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传