我有一个在网络服务器上运行的 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/