nostalgia Posted January 15, 2010 Share Posted January 15, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188611-trouble-with-curl_exec/ Share on other sites More sharing options...
laffin Posted January 15, 2010 Share Posted January 15, 2010 curl_setopt($ch, CURLOPT_POSTFIELDS, array('test'=>'test'); Quote Link to comment https://forums.phpfreaks.com/topic/188611-trouble-with-curl_exec/#findComment-995790 Share on other sites More sharing options...
nostalgia Posted January 18, 2010 Author Share Posted January 18, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188611-trouble-with-curl_exec/#findComment-997387 Share on other sites More sharing options...
nostalgia Posted January 18, 2010 Author Share Posted January 18, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188611-trouble-with-curl_exec/#findComment-997392 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.