简体   繁体   English

如何在不使用 sockets 的情况下在 C ++ 中发送 POST 请求

[英]How can I send a POST request in C ++ without using sockets

I have python code that sends a POST request and gets a json, I need to rewrite it in C ++ (Windows 10, Visual Studio 2019).我有 python 代码发送 POST 请求并获得 json,我需要在 C ++(Windows 10,Visual Studio 2019)中重写它。 I don't understand what tools can really do everything I need without complicating the code.我不明白什么工具可以真正完成我需要的一切而不会使代码复杂化。

There will be a console application that must send a request to send or receive data, more precisely a video stream.将有一个控制台应用程序必须发送请求以发送或接收数据,更准确地说是视频 stream。 I read about Boost.Asio, but it seems to work only with sockets, is there any way without them?我读到了 Boost.Asio,但它似乎只适用于 sockets,没有它们有什么办法吗? At first I wanted to use it, as the most famous.起初我想用它,因为它最有名。 I read about сurl, but it hasn't been updated for a long time, is it still relevant?看了关于 сurl 的文章,但是很久没更新了,还有用吗?

    headers_predict = {
        "Content-type": "application/json;charset=UTF-8",
        "Accept": "application/json",
        "X-Session-ID": session_id
        }
    data_predict = {
      "audio": {
          "data": sound_base64,
          "mime": "audio/pcm16"
          },
      "package_id": ""
      }
    url = 'https://cp.speechpro.com/recognize'
    r = requests.post(url, headers=headers_predict, 
    data=json.dumps(data_predict))
    print('Response: %s' % r.text)

I wouldn't want to use sockets, because I don't understand them.我不想使用 sockets,因为我不了解它们。 I need to be able to set the header and data as a json.我需要能够将 header 和数据设置为 json。

sockets, is there any way without them? sockets,没有它们有什么办法吗?

Technically, HTTP does not specify the underlying transport protocol and it can work with any sort of streaming transport.从技术上讲,HTTP 没有指定底层传输协议,它可以与任何类型的流传输一起使用。 You could for example write the request into a file.例如,您可以将请求写入文件。

But, if you currently use TCP and don't want to change that, then you must use sockets.但是,如果您当前使用 TCP 并且不想更改它,那么您必须使用 sockets。 You don't need to interact with them directly if you use an existing HTTP client library.如果您使用现有的 HTTP 客户端库,则无需直接与它们交互。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM