POST to url with cURL
Posted: Fri Oct 07, 2011 4:22 pm
I'm attempting to write a simple script that given a name will automatically POST that information to another site, and return the results.
This is the site that i'm looking at:
http://euw.leagueoflegends.com/ladders/solo-5x5
and the form i'm interested in is
the php code i've thrown together to try and accomplish my aim is:
Which i believe should work... However, $response returns blank. If i remove the field "form_id=ladders_filter_form"i get a page response (but it hasn't performed a search as it requires the form_id)
Any advice or insight into why this is occuring would be appreciated.
Many thanks
This is the site that i'm looking at:
http://euw.leagueoflegends.com/ladders/solo-5x5
and the form i'm interested in is
after playing around with it on my localhost, i've found that the highlighted elements are those that need to be POSTed, the other inputs don't seem to make a difference.<form id="ladders-filter-form" method="post" accept-charset="UTF-8" action="/ladders/solo-5x5">
<div>
<input id="edit-submit" class="form-submit submit_button" type="submit" value="Search" name="op">
<div id="edit-player-wrapper" class="form-item">
<input id="edit-player" class="form-text" type="text" value="" size="60" name="player" maxlength="128">
</div>
<input id="edit-ladder-id" type="hidden" value="3" name="ladder_id">
<input id="form-d48014308d4389f847f6bb8bff3a28fa" type="hidden" value="form-d48014308d4389f847f6bb8bff3a28fa" name="form_build_id">
<input id="edit-ladders-filter-form" type="hidden" value="ladders_filter_form" name="form_id">
</div>
</form>
the php code i've thrown together to try and accomplish my aim is:
Code: Select all
$fields = "op=Search&player=grizzzzzzzzzz&form_id=ladders_filter_form";
$url = "euw.leagueoflegends.com/ladders/solo-5x5";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$response = curl_exec($ch);
curl_close ($ch);
echo $response;
Any advice or insight into why this is occuring would be appreciated.
Many thanks