我正在使用 libcurl 向我的 Web 服务器上的 index.php 文件发出简单的 http 发布请求,该文件具有以下简单的代码将发布数据写入文件
if (isset($_POST['abc'])){
$log="abc.log";
$h=fopen($log,"w");
fwrite($h,$_POST['abc']);
fclose($h);
}
而我编写的实现http post请求的c++代码如下
CURL *curl;
CURLcode res;
curl=curl_easy_init();
string url=AnsiString("http://127.0.0.1/curl/index.php?abc=123").c_str();
string data="abc=3434";
if (curl) {
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS,AnsiString("abc=3434").c_str());
curl_easy_setopt(curl, CURLOPT_URL,AnsiString("http://127.0.0.1/curl/index.php").c_str());
res=curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
首先,启用发布curl_easy_setopt(curl, CURLOPT_POST, 1);
其次,如果我调试此代码,我会CURL_OK
在(返回值)中获得状态,res
并且每次我运行代码监控时都会建立 TCP 127.0.1:80,netstat -ano 15
但文件abc.log
为空
这有什么问题??你没有任何想法指出我正确的方式吗?
先感谢您!