1

我一直在寻找在外部网站上做自动化工作。有人告诉我我应该使用 curl,所以我想我在问 curl 是否是一个选项?我将如何使用这些输入字段来做到这一点:

name="fname"
name="lname"
name="bio"
name="website"
name="email"
name="password"
name="Cpassword"
name="token"
name="submit"
4

1 回答 1

1

是的,在 cron 作业示例中正确使用 curl 集告诉您。

//The data
$data = array(
    "fname" => "Mark",
    "lname" => "Jones",
    "Bio" => "Hi i like rose's because they smell nice",
    "website" => "http://mysite.com",
    "email" => "mark@mysite.com",
    "password" => "mypassword",
    "token" => "your token",
    "Agent" => "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5"
);

//External site direct link
$external_site = "http://external-site.com";

//Input field names with data ready
$input_fields = "fname=".$data['fname']."&lname=".$data['lname']."&Bio=".$data['bio']."&website=".$data['website']."&email=".$data['email']."&password=".$data['password']."&Cpassword=".$data['password']."&token=".$data['token']."&submit=";

//Do the curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $external_site);
curl_setopt($ch, CURLOPT_USERAGENT, $data['Agent']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $input_fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$done = curl_exec ($ch);
curl_close($ch);

有关 curl 的更多信息,请访问http://php.net/manual/en/book.curl.php并且对于 cron 作业的大多数主机提供现成的 cron 功能以使用 XD。

于 2013-02-27T10:50:52.817 回答