Reputation: 17370
i want to submit any IP address to this site with cUrl
. my cUrl options could not work correctly:
$h = curl_init();
curl_setopt($h, CURLOPT_URL, "http://www.whatismyip.com/ip-whois-lookup/");
curl_setopt($h, CURLOPT_POST, true);
curl_setopt($h, CURLOPT_POSTFIELDS, array(
'IP' => '2.179.144.117',
'submitted' => 'submitted'
));
curl_setopt($h, CURLOPT_HEADER, false);
curl_setopt($h, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($h);
echo $result;
Upvotes: 0
Views: 84
Reputation: 2459
Give your array data with http_build_query()
function so that, it can be decoded correctly on requested IP:
curl_setopt($h, CURLOPT_POSTFIELDS, http_build_query(
array(
'IP' => '2.179.144.117',
'submitted' => 'submitted'
)
));
// echo http_build_query(array('IP' => '2.179.144.117', 'submitted' => 'submitted'));
// outputs: IP=2.179.144.117&submitted=submitted and this will be added to the end of
// the requested URL in GET request.
Upvotes: 1
Reputation: 1555
A quick check on the headers sent to that webpage, reveals that the "submitted" post variable should be set to true, not to submitted.
Remark: please note that whatismyip.com probably does not allow access to its tool by means of scraping.
Upvotes: 0