http post is not working using cUrl (libcurl)
-
04-12-2019 - |
Вопрос
I'm making simple http post request using libcurl to index.php file on my web server that has the following simple code writing post data to a file
if (isset($_POST['abc'])){
$log="abc.log";
$h=fopen($log,"w");
fwrite($h,$_POST['abc']);
fclose($h);
}
while my written c++ code implementing http post request is the following
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);
}
First, posting is enabled curl_easy_setopt(curl, CURLOPT_POST, 1);
Second, if I debug this code i get CURL_OK
status in res
(return value)
and also TCP 127.0.1:80 will be established everytime i run the code monitoring via netstat -ano 15
but the file abc.log
is empty
What's wrong with this?? Haven't you any idea pointing me to the right way?
Thank you in advance!
Решение
Sending CURLOPT_POSTFIELDSIZE
helped!
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,data.Length());
Apache log says it's ok you've sent POST
127.0.0.1 - - [03/Mar/2012:17:39:06 +0500] "POST /curl/post.php HTTP/1.1" 200 -