Help With CURL And GET Forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • devranger

    #1

    Help With CURL And GET Forms

    I have used curl_setopt($ch , CURLOPT_POST, true); and curl_setopt($ch ,
    CURLOPT_POSTFIE LDS, $data); on post forms to retrun results, but what
    about a GET Form Method? How do you deal with these with curl? The
    same commands?

    The particular instance I am dealing with is a store locator and it is
    not as easy as just calling the url with the variables becasue it runs
    some script behind the scene that does a bunch of calculations for
    calculating the lat. and lon. of the store so it can call a mappoint
    map. After the form submission the url is a mess and pretty customized
    to the zip code searched with lat and lon.

    Here is an example of the form action:
    <form Method="GET"
    Action="http://go.mappoint.net/ccc/Geocode.aspx?br and=h&amp;FC=cc c&amp;FC=ccc"
    Name="OutsideUS ">

    Here is an mocked up example of a resulting URL after the form
    submission:



    How would I deal with this in curl? Your help is much appreciated.

    Thank you!

  • Erwin Moller

    #2
    Re: Help With CURL And GET Forms

    devranger wrote:
    I have used curl_setopt($ch , CURLOPT_POST, true); and curl_setopt($ch ,
    CURLOPT_POSTFIE LDS, $data); on post forms to retrun results, but what
    about a GET Form Method? How do you deal with these with curl? The
    same commands?
    >
    The particular instance I am dealing with is a store locator and it is
    not as easy as just calling the url with the variables becasue it runs
    some script behind the scene that does a bunch of calculations for
    calculating the lat. and lon. of the store so it can call a mappoint
    map. After the form submission the url is a mess and pretty customized
    to the zip code searched with lat and lon.
    >
    Here is an example of the form action:
    <form Method="GET"
    >
    Action="http://go.mappoint.net/ccc/Geocode.aspx?br and=h&amp;FC=cc c&amp;FC=ccc"
    Name="OutsideUS ">
    >
    Here is an mocked up example of a resulting URL after the form
    submission:
    >
    >
    http://go.mappoint.net/ccc/PrxResult...=isccc&brand=a
    >
    How would I deal with this in curl? Your help is much appreciated.
    >
    Thank you!
    Hi,

    I think just assembling the URL should do the trick.
    So just add all name/value pairs you have to the url.
    eg:
    $baseURL = "http://go.mappoint.net ?";
    // assuming you have your info in an assoc-array:
    $myNameValues = array(
    "LOC" ="23.327467234" ,
    "CT" ="34.8793276 89"
    );

    // urlencode all values
    $urlEncodedPart s = array();
    foreach ($myNameValues as $key =$value){
    $urlEncodedPart s = $key."=".urlenc ode($value);
    }

    // add to baseurl
    $baseURL .= implode("&",$ur lEncodedParts );


    Then just use the baseurl in CURL without POST-options.

    (Not tested)

    Regards,
    Erwin Moller

    Comment

    Working...