返回> 网站首页 

某设备http协议标头带空格问题解决

yoours2023-08-11 12:40:01 阅读 1449

简介一边听听音乐,一边写写文章。

一、问题来源

        由于设备是从第三方处购买,厂家不提供技术支持。根据官方网站公开下载的通讯协议文档实现通讯。

二、http协议

        使用curl请求报错,不能接收到回应数据;同样数据使用postman测试能看到响应信息。

        分析响应信息发现在 Content-Type 标头前面多了一个空格导致接收解析失败。

三、libhv开源库

         由于存在已知问题,要解决正常通讯。

         需要修改pclibhv-master/http/http_parser.c文件1212行,跳过空格,如下:

        c = TOKEN(ch);

        if (c == 0) continue;

四、http示例

        string jstr;

        auto resp = requests::post("http://192.168.1.20/login");

        if (resp != NULL) {

            printf("%d %s\r\n", resp->status_code, resp->status_message());

            printf("%s\n", resp->body.c_str());

        }

五、curl修改方法

      修改curl-8.2.1\lib\http.c文件,第3990行。

    int space = 0;

    if (str_start[0] == ' ')

        space = 1;

    result = Curl_dyn_addn(&data->state.headerb, str_start + space, full_length);

    if(result)

      return result;


微信小程序扫码登陆

文章评论

1449人参与,0条评论