Php cURL未能提交POST数据

Php cURL未能提交POST数据,php,forms,curl,Php,Forms,Curl,我试图提交一个带有cURL的简单表单。在获得登录cookie并提交我想要的数据后,我得到一个随机响应,表单未能提交。以下是浏览器提交表单时的外观: formPost:cur_product_form_new_86286 curCheckbox:Y C2cProductsListing[business_hr_from]:10:00:00 C2cProductsListing[business_hr_to]:09:30:00 C2cProductsListing[online_hr]:35 C2c

我试图提交一个带有cURL的简单表单。在获得登录cookie并提交我想要的数据后,我得到一个随机响应,表单未能提交。以下是浏览器提交表单时的外观:

formPost:cur_product_form_new_86286
curCheckbox:Y
C2cProductsListing[business_hr_from]:10:00:00
C2cProductsListing[business_hr_to]:09:30:00
C2cProductsListing[online_hr]:35
C2cProductsListing[offline_hr]:16
C2cProductsListing[non_business_hr]:17
C2cProductsListing[actual_quantity]:25000
C2cProductsListing[minimum_quantity]:25000
C2cProductsListing[products_base_currency]:USD
C2cProductsListing[products_price]:88
delivery[1]:1
C2cProductsListing[c2c_products_listing_id]:86286
以下是我提交表格时的情况:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.g2g.com/sell/manageListingInfo'); // open a protected page
curl_setopt($ch, CURLOPT_REFERER, 'http://www.g2g.com/sell/manageListing?game=2522&product_type=19248');
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13");
$data = array(
    'formPost' => 'cur_product_form_new_86286',
    'curCheckbox' => 'Y',
    'C2cProductsListing' => array(
        'business_hr_from' => '09:00:00',
        'business_hr_to' => '08:30:00',
        'online_hr' => '35',
        'offline_hr' => '16',
        'non_business_hr' => '17',
        'actual_quantity' => '25000',
        'minimum_quantity' => '25000',
        'products_base_currency' => 'USD',
        'products_price' => '25',
        'c2c_products_listing_id' => '86286'
    ),
    'delivery' => array(
        '1' => '1'
    )
);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_REFERER, 'http://www.g2g.com/sell/manageListing?game=2522&product_type=19248');
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
print_r(curl_getinfo($ch));

curl_close($ch);
这是我得到的完全随机响应:

Array ( [url] => http://www.g2g.com/sell/manageListingInfo [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => 0 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array ( ) )
我刚刚发布的数组是打印(curl\u getinfo($ch))的结果。。我怎么会在这里结束?我使用所有必要的数据完全模拟了浏览器请求(除了它是cURL而不是实际的浏览器),但是表单似乎没有提交?

您调用它不是为了实际执行查询。然后调用
curl\u getinfo
。如果要返回数据,请使用返回值
curl\u exec
而不是
curl\u getinfo
。例如:

$data = curl_exec($ch);
echo $data;

它可能很简单,比如打开表单时服务器上设置的会话变量,以避免绕过表单提交。@jeroen我对得到的结果过于困惑。据我所知,我已经完全克隆了表单数据。在我做所有这些之前,我必须登录,获取cookie,然后尝试提交它。浏览器上的相同过程只需获取cookie还是获取表单?人们可以使用各种各样的技巧来避免自动提交表单,例如设置会话变量、计时请求表单和提交表单所需的时间(太快,无效)等。如果是这样设置的,那么要让表单成功提交将需要大量的尝试和错误。@jeroen只需获取cookies,所以我刚刚登录。他们没有API可以替代吗?我刚刚登录了。这改变了结果,我得到了一些更奇怪的东西,比如(太长了,无法评论),这没有什么“奇怪”,只是一些关于远程服务器给你的响应的信息。上面写着
url:http://www.g2g.com/account/login
表示站点已将您重定向回其登录表单,因为您传递给它的数据并不能证明您已经成功登录。getinfo显示有关传输的信息,而不是它返回的数据。[http_code]=>200表示http请求成功。@CBroe它是否使用了我一分钟前抓取的cookie?好吧,也许cookie还不够——正如jeroen在另一篇评论中所说的,有更多的东西可以区分使用普通浏览器的用户和使用机器人的用户。(我将首先查看浏览器发送的所有请求头,然后尝试实现那些尚未随cURL请求一起发送的请求头。)