如何在打字稿中通过ssdp发送http请求

How to send http request via ssdp in typescript

我正在学习本教程: https://sdkdocs.roku.com/display/sdkdoc/External+Control+API ...尝试通过 ssdp / http get 获取设备列表。

        let query: string = "M-SEARCH * HTTP/1.1\r\n" +
            "HOST: 239.255.255.250:1900\r\n" +
            "MAN: \"ssdp:discover\"\r\n" +
            "ST: roku: ecp\r\n\r\n";

        this.http
            .get(query)
            .map(res => res.json())
            .subscribe(
            (data) => this.devices = data,
            (err) => this.error = err);

... 但我收到 404 错误(另外,localhost 被附加到字符串中):

Failed to load resource: the server responded with a status of 404 (Not Found)

http://localhost:52125/M-SEARCH%20*%20HTTP/1.1HOST:%20239.255.255.250:1900MAN:%20%22ssdp:discover%22ST:%20roku:%20ecp

SSDP 使用 HTTPU 或基于 UDP 的 HTTP。 Node 的 HTTP 客户端仅通过 TCP 发送数据。您需要使用 udp 套接字手动发送并侦听数据,或者使用预先存在的库,例如 node-ssdp.