【问题标题】:sending http/2 POST request in Node.js在 Node.js 中发送 http/2 POST 请求
【发布时间】:2021-08-18 19:18:17
【问题描述】:

如何在 Node.js 中发送 http/2 发布请求? 我想发送以下请求。

curl --http2 "POST" "http://hostname:8088/query-stream" -d $'{"sql": "SELECT * FROM `USERPROFILE` EMIT CHANGES;", "properties": {"ksql.streams.auto.offset.reset": "earliest" } }'

【问题讨论】:

    标签: node.js rest http2 ksqldb node-kafka-streams


    【解决方案1】:

    fetch-h2支持http/2:

    import { fetch } from 'fetch-h2'
    
    const url = 'https://hostname:8088/query-stream'
    const method = 'POST';
    const json = {"sql": "SELECT * FROM `USERPROFILE` EMIT CHANGES;", "properties": {"ksql.streams.auto.offset.reset": "earliest" } };
     
    const response = await fetch( url, { method, json } );
    

    请注意,默认情况下 fetch-h2 使用 http/1.1 作为 http:// 地址。 更改 URL 或配置 fetch-h2 以显式使用 http/2,即使对于 http:// 请求也是如此。

    【讨论】:

    • 感谢您的回答,但我认为获取发送 http/1.1 请求。不支持 http/2 在该示例中的响应是这样 { '@type': 'generic_error', error_code: 40004, message: 'This endpoint is only available when using HTTP2' } ➜
    • 你是对的。我没有意识到这一点。我用应该支持 http/2 的解决方案更改了我的答案
    • 谢谢。我也使用了 fetch-h2,它对该请求也有问题。因为该请求将打开连接,如果有任何更改将发送一个事件,如套接字。对该示例的响应如下:在建立安全 TLS 连接之前已断开客户端网络套接字
    猜你喜欢
    • 2016-03-31
    • 2018-07-07
    • 2021-08-16
    • 2016-04-08
    • 2012-03-27
    • 1970-01-01
    • 1970-01-01
    • 2011-03-20
    相关资源
    最近更新 更多