Jump to content

Recommended Posts

Hey all.  I'm at my wit's end.  I've stripped my app down to the bare minimum, and I still can't determine what the problem is.  I'm trying to send a POST to a server.  When I use a <form> post, it works fine, and I see the POST data at the server.  When I do it with curl, curl_exec() never returns.

 

I'm running an HTTP sniffer, and I do not see the HTTP request when using curl.  I do see it when using the <form> post.

 

I also tried just POSTing back to the same page.  In this case, curl_exec() does not hang, but it doesn't seem to work properly either.  See below.

 

Here's what the code looks like:

<?php
echo "<p>START</p>";

$ch = curl_init("http://www.myserver.com/temp.php"); // This file

if (!$ch)
{
echo "<p>curl_init() failed</p>";
}
else
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "test=test&");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1);

$recData = curl_exec($ch);

curl_close($ch);

if (!$recData)
{
	echo "<p>recData == FALSE</p>";
}
else
{
	echo "<p>".htmlspecialchars($recData)."</p>";
}
}
echo "<p>DONE</p>";
?>

 

And here's what gets displayed when I execute that script:

 

START

<head> <meta http-equiv="refresh" content="0;url=http:/ifastnet.com/notify/2.php" /> </head> <html> <body> <script LANGUAGE="JavaScript"> window.location="http://ifastnet.com/notify/2.php"; </script> <!-- 399 310 772 188 121 747 908 375 658 989 471 891 842 282 539 788 863 399 310 772 188 121 747 908 375 658 989 471 891 842 282 539 788 863 399 310 772 188 121 747 908 375 658 989 471 891 842 282 539 788 863 526 640 917 51 415 140 573 716 965 688 395 829 76 810 801 733 244 95 205 283 488 189 705 173 743 574 947 608 694 973 886 298 223 449 99 309 936 432 209 623 454 399 310 772 188 121 747 908 375 658 989 471 891 842 282 539 788 863 399 310 772 188 121 747 908 375 658 989 471 891 842 282 539 788 863 399 310 772 188 121 747 908 375 658 989 471 891 842 282 539 788 863 526 640 917 51 415 140 573 716 965 688 395 829 76 810 801 733 244 95 205 283 488 189 705 173 743 574 947 608 694 973 886 298 223 449 99 309 936 432 209 623 454 399 310 772 188 121 747 908 375 658 989 471 891 842 282 539 788 863 399 310 772 188 121 747 908 375 658 989 471 891 842 282 539 788 863 399 310 772 188 121 747 908 375 658 989 471 891 842 282 539 788 863 526 640 917 51 415 140 573 716 965 688 395 829 76 810 801 733 244 95 205 283 488 189 705 173 743 574 947 608 694 973 886 298 223 449 99 309 936 432 209 623 454 399 310 772 188 121 747 908 375 658 989 471 891 842 282 539 788 863 399 310 772 188 121 747 908 375 658 989 471 891 842 282 539 788 863 399 310 772 188 121 747 908 375 658 989 471 891 842 282 539 788 863 526 640 917 51 415 140 573 716 965 688 395 829 76 810 801 733 244 95 205 283 488 189 705 173 743 574 947 608 694 973 886 298 223 449 99 309 936 432 209 623 454 399 310 772 188 121 747 908 375 658 989 471 891 842 282 539 788 863 399 310 772 188 121 747 908 375 658 989 471 891 842 282 539 788 863 399 310 772 188 121 747 908 375 658 989 471 891 842 282 539 788 863 526 640 917 51 415 140 573 716 965 688 395 829 76 810 801 733 244 95 205 283 488 189 705 173 743 574 947 608 694 973 886 298 223 449 99 309 936 432 209 623 454 --> </body> </html> <BR clear="all"> <HR noshade size="1px"> <ADDRESS> Generated Fri, 15 Jan 2010 20:53:12 GMT by demil1.byetcluster.com (Lusca/LUSCA_HEAD) </ADDRESS> </BODY></HTML>

DONE

 

Any help is welcome!  Thanks,

 

-Joe

Link to comment
https://forums.phpfreaks.com/topic/188611-trouble-with-curl_exec/
Share on other sites

Thank you for the reply, but that didn't seem to make a difference.  Could you maybe expand a little on why you suggested that change?  I thought POSTFIELDS wanted a string pre-formatted as in all of the examples I've found online:

define('POSTVARS', 'listID=29&request=suba&SubscribeSubmit=Subscribe&EmailAddress=');
curl_setopt($ch, CURLOPT_POSTFIELDS    ,POSTVARS.$Email);

 

Either way, would a badly formed POST payload cause curl_exec() to hang?

 

Thanks,

 

-Joe

Hmm...I'm sniffing around with Wireshark now.  When I load the page with the code above, I'm seeing a GET but no post.  When I add a form with a button

 

<form action="temp.php" method="post">
<input type="submit" value="Press me">
</form>

 

and press the button, I do see a POST and 200/OK reply.

 

Weird.

 

-Joe

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.