libcurl を使用して、web サーバー上の index.php ファイルに単純な http 投稿要求を作成しています。このファイルには、投稿データをファイルに書き込む次の単純なコードがあります。
if (isset($_POST['abc'])){
$log="abc.log";
$h=fopen($log,"w");
fwrite($h,$_POST['abc']);
fclose($h);
}
httpポストリクエストを実装する私の書いた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);
第 2 に、このコードをデバッグすると (戻り値) でCURL_OK
ステータスが返されres
、TCP 127.0.1:80 が確立され、コード監視を実行するたびに確立されnetstat -ano 15
ますが、ファイルabc.log
は空です。
これの何が問題なのですか?? 私に正しい道を示しているとは思いませんか?
前もって感謝します!