0

如何在 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>
4

1 回答 1

0

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

curl_setopt($ch, CURLOPT_REFERER, 'http://www.gumtree.pl');
于 2013-09-11T23:28:48.043 回答