如何在gumtree上发送表格?

时间:2013-09-11 23:15:13

标签: php forms curl

如何在Gumtree上发送表格?我正在尝试,因为我需要使用curl / php(或perl / Java)来完成它。 在发送之前我不关心电子邮件激活或帐户授权。

现在我正在使用它:

<php

(...)
// Setting POST data

// Type of announcement
// HTML code of this form radio button:
// <input type="radio" name="AdType" value="2" checked>
$postData["AdType"]    =    "2";
(...)


// Sending form using cUrl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.gumtree.pl/c-ConfirmAd"); //or c-PostAd
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.gumtree.pl');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_HEADER, 1);
//curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('HeaderName: HeaderValue', 'Expect:     \r\n')); // or //Expect: 100-continue


$response = curl_exec ($ch);

//print_r($response);

// Write response to log.html
$file = 'formByCURLandPHP.out.html';
file_put_contents($file, $response);

exit();

我得到的是:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <title>417 - Expectation Failed</title>
 </head>
 <body>
  <h1>417 - Expectation Failed</h1>
 </body>
</html>

1 个答案:

答案 0 :(得分:0)

你错过了一个:在网址http://

curl_setopt($ch, CURLOPT_REFERER, 'http://www.gumtree.pl');