Reputation: 1400
I'm trying to submit a simple form with cURL. After obtaining the login cookie and submitting the data I want, I get a random response and form fails to submit. Here is what it looks like when browser submits a form:
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
Here is what it looks like when I submit the form:
$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);
And here is the completely random response I get:
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 ( ) )
The array I just posted is result of print_r(curl_getinfo($ch))
. How do I end up here? I emulated the browser request fully (aside from it being cURL and not the actual browser) using all the data necessary, yet the form doesn't seem to be submitted?
Upvotes: 0
Views: 269
Reputation: 930
You're not calling curl_exec
to actually execute the query. Call curl_getinfo
afterwards. If you want the data returned use the return value of curl_exec
instead of curl_getinfo
. For example:
$data = curl_exec($ch);
echo $data;
Upvotes: 1