php - 将数据从 C++ 程序发送到 PHP Web 服务器

标签 php c++ linux bash sockets

我有一个在网络服务器上运行的 php 脚本,以便对数据库执行一些插入操作。此脚本接收一些加密数据,对其进行解密并将其推送到数据库中。

负责发送这个数据的是一个C++程序(Linux下运行),这个程序每5秒发送一次不超过40个字符的信息。

我正在考虑调用一些打开 URL ( http://myserver.com/myscript.php?message=adfafdadfasfasdfasdf ) 并通过参数接收消息的 bash 脚本。

我不需要复杂的解决方案,因为我只需要打开 URL,它是一个单向通信 channel 。

一些简单的解决方案来做到这一点?

谢谢!

最佳答案

一个更强大的解决方案是使用 libcurl,它可以让您 open a http connection in a few lines .这是链接中的自包含示例:

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
    /* example.com is redirected, so we tell libcurl to follow redirection */ 
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

    /* Perform the request, res will get the return code */ 
    res = curl_easy_perform(curl);
    /* Check for errors */ 
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));

    /* always cleanup */ 
    curl_easy_cleanup(curl);
  }
  return 0;
}

关于php - 将数据从 C++ 程序发送到 PHP Web 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14880057/

相关文章:

javascript - 如何将单选按钮更改为 Bootstrap 按钮

c++ - 如何做我自己的自定义运行时错误类?

c++ - 比较使用不同分配器的 STL 字符串

c++ - 无法将 'const T*' 转换为 'T*&&'

linux - 在 redhat 中安装 make - 找不到 make 命令

Linux - 嵌套中断

php - 强制浏览器缓存 .php

php - 数组键作为用于插入的 mysql 列名?

PHP:MySQL 错误钩子(Hook)?

linux - 匹配模式的 mv 文件夹