简体   繁体   English

使用curl将数据发布到php页面

[英]POST data to a php page using curl

There is a site http://www.kovansports.com/bookonline/ , and I think the page is an index.php because when I typed that filename in I do not get a 404. 有一个站点http://www.kovansports.com/bookonline/ ,我认为该页面是一个index.php,因为当我在其中键入该文件名时我没有得到404。

In that page, there is a label 'Schedule For', where you can choose a date and press Go. 在该页面上,有一个标签“ Schedule For”,您可以在其中选择日期并按Go。 The form action references back to the same page ( http://www.kovansports.com/bookonline/ ), and presents the table associated with the new date chosen. 表单操作返回到同一页面( http://www.kovansports.com/bookonline/ ),并显示与所选新日期关联的表。

I am testing a PHP page to post a date to the site above, so that I get the table for the date I want, for scraping information. 我正在测试一个PHP页面,将一个日期发布到上面的站点,以便获取所需日期的表格,以获取信息。

The code that I used is below, and it is not working somehow, as I am faced with a 404 error. 我使用的代码如下,由于我遇到404错误,因此无法正常工作。 First time doing this, so please let me know what I am doing wrong and the best way to achieve my objective. 第一次这样做,所以请让我知道我做错了什么以及实现目标的最佳方法。 Thanks! 谢谢!

<?php
$urltopost = "http://www.kovansports.com/bookonline/index.php";
$datatopost = "date=07-Aug-13&loadschedule=1";

$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, false);
$returndata = curl_exec ($ch);
curl_close ($ch);
print $returndata; //display the reuslt
?>
$urltopost = "http://www.kovansports.com/bookonline/";

Works fine without the index.php. 没有index.php即可正常工作。 They're probably using a .htaccess file to rewrite the URL. 他们可能正在使用.htaccess文件重写URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM