Jump to content

cURL Posting Woes


agirman

Recommended Posts

Hello there,

I was hoping someone might have some insight as to why my cURL call isn't working.  Basically, I'm trying to POST some variables to a php script, and it would seem like the curl request is hitting the form, but the server script isn't getting any post variables.  I have tried this on a couple of different servers, but here's the problem: start with two simple scripts, curltest_client and curltest_server.  The client simply sends a curl POST request to the server, and the server simply reads its $_POST array and echoes it out.  No matter what curl options I seem to try, I can't seem to access any variables in the results (though my curl dump says it's gone out).  Maybe it's an apache setting or something?

I'm running:
apache 2 (forget the version)
php 4.3.10
linux (FC5)
curl 7.15.4
mysql 5.0.24a
[tt]
//===curltest_client.php===
<?php
  echo "starting up...<br/>\n";
 
  $curl_log = fopen('/home/test/curl_log.txt', 'w');
 
  $ch1 = curl_init();
 
  $postfields = urlencode("query=this is the post content\n\r");

        curl_setopt($ch1, CURLOPT_VERBOSE, true);
curl_setopt($ch1, CURLOPT_STDERR, $curl_log);

curl_setopt($ch1, CURLOPT_POST, true);
curl_setopt($ch1, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch1, CURLOPT_URL, 'localhost/test/curltest_server.php');

curl_setopt($ch1, CURLOPT_FAILONERROR,    true);
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch1, CURLOPT_TIMEOUT, 200);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, false);

$header[] = "Content-Type: text/xml";
curl_setopt($ch1, CURLOPT_HTTPHEADER, $header);

$new_result = curl_exec($ch1);
$curl_error = curl_error($ch1);
$curl_errno = curl_errno($ch1);
$curl_info = curl_getinfo($ch1);
curl_close($ch1);

echo "\n<br/>result: " . $new_result;
echo "\n<br/>curl error: " . $curl_error;
echo "\n<br/>curl errno: " . $curl_errno;
?>
Link to comment
https://forums.phpfreaks.com/topic/26750-curl-posting-woes/
Share on other sites

[tt]
//===curltest_server.php===
<?php
echo "hi, this is the server.<br/>\n";

if(empty($_POST)) {
echo "\$_POST not set... exiting.<br/>\n";
exit(0);
}
foreach($_POST as $key => $value) {
echo "&nbsp;&nbsp;$key => $value<br/>\n";
}

echo "peace out!<br/>\n";
?>
[/tt]

The output is always
[tt]
starting up...

result: hi, this is the server.
$_POST not set... exiting.

curl error:
curl errno: 0
[/tt]

Anyone have any insights as to what I'm doing wrong?  Any help would be appreciated.  Sorry for splitting the message up, the forum won't let me post part of it--the contents of $curl_log.  There seems to be some sort of illegal character in there that's causing my connection to the forums to get reset :-X.

Thank you,

Alex.
Link to comment
https://forums.phpfreaks.com/topic/26750-curl-posting-woes/#findComment-122311
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.