cURL / Mailing Lists / curl-library / Single Mail

curl-library

How to send POST form?

From: Jung-Mu Tang <jmtang_at_us.ibm.com>
Date: Tue, 20 Nov 2001 13:07:18 -0500

Hi:
I am trying to get map from mapquest with gps data. Here is the form I
tried to send and the code I worte. For some reason, it did'nt return the
page I expected.
I suspected that input data were not sent correctly. Please help me out.

/*
   <FORM action="http://www.mapquest.com/cgi-bin/ia_find" method="POST">
      <INPUT type="hidden" name="link" value="btwn/twn-map_results">
      <INPUT type="hidden" name="event" value="latlng_search">
      <INPUT type="hidden" name="type" value="dec">
      <INPUT type="hidden" name="uid" value="ud.4zcmb72qcvdoa:2x0ft5gzbw">
      <INPUT type="hidden" name="random" value="552">
      <INPUT type="hidden" name="SNVData" value
="3mad3-9.fy%28at2u67_%29f82u67%3bah7-%3d%3a%28_%3d%3abad672%3d%3d1su672%3d0,rb%3b7%3bb5m-r2qfj5m%3be10h%284">
      <INPUT type="Text" name="lat" size="20" maxlength="12" tabindex=8>
      <INPUT type="Submit" name="Find Map" value="Get Map" class
="submitButton" tabindex=10>
      <INPUT type="Text" name="lng" size="20" maxlength="12" tabindex=9>
   </FORM>
*/
int main(int argc, char **argv) {
   struct HttpPost* post = NULL;
   struct HttpPost* last = NULL;
   FILE *htmlfile;
   CURL *curl_handle;

   // form data <input type="hidden" name="link" value
="btwn/twn-map_results">
   char *link_value="btwn/twn-map_results";
   //char *link_value="btwn/twn-map_latlong_degrees_form";
   char *event_value="latlng_search";
   char *type_value="dec";
   char *uid_value="u4t9s1qd_3vbldha:2x56tlqabl";
   char *random_value="657";
   char *SNVData_value=

"3mad3-9.fy%28at2u67_%29f82u67%3bah7-%3d%3a%28_%3d%3abad672%3d%3d1su672%3d0,rb%3b7%3bb5m-r2qfj5m%3be10h%284";
   char *lat_value="41.103731";
   char *lng_value="-73.796341";
   char *url ="http://www.mapquest.com/cgi-bin/ia_find";

     // Add gps data
   curl_formadd(&post, &last, CURLFORM_COPYNAME, "link",
                CURLFORM_PTRCONTENTS, link_value, CURLFORM_END);
   curl_formadd(&post, &last, CURLFORM_COPYNAME, "event",
                CURLFORM_PTRCONTENTS, event_value, CURLFORM_END);
   curl_formadd(&post, &last, CURLFORM_COPYNAME, "type",
                CURLFORM_PTRCONTENTS, type_value, CURLFORM_END);
   curl_formadd(&post, &last, CURLFORM_COPYNAME, "uid",
                CURLFORM_PTRCONTENTS, uid_value, CURLFORM_END);
   curl_formadd(&post, &last, CURLFORM_COPYNAME, "random",
                CURLFORM_PTRCONTENTS, random_value, CURLFORM_END);
   curl_formadd(&post, &last, CURLFORM_COPYNAME, "SNVData",
                CURLFORM_PTRCONTENTS, SNVData_value, CURLFORM_END);
   curl_formadd(&post, &last, CURLFORM_COPYNAME, "lat",
                CURLFORM_PTRCONTENTS, lat_value, CURLFORM_END);
   curl_formadd(&post, &last, CURLFORM_COPYNAME, "lng",
                CURLFORM_PTRCONTENTS, lng_value, CURLFORM_END);
   /* Fill in the submit field too, even if this is rarely needed */
   curl_formadd(&post,
                &last,
                CURLFORM_COPYNAME, "submit",
                CURLFORM_COPYCONTENTS, "send",
                CURLFORM_END);

   // init the curl session
   curl_handle = curl_easy_init();

   // what URL that receives this POST
   curl_easy_setopt(curl_handle, CURLOPT_URL, url);

   // Set the form info
   htmlfile = fopen("mq.htm", "w");
   curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, post);
   curl_easy_setopt(curl_handle, CURLOPT_FILE, htmlfile);
   curl_easy_perform(curl_handle);

   /* always cleanup */
   curl_easy_cleanup(curl_handle);

   /* then cleanup the post chain */
   curl_formfree(post);
}

Regards,
Jung-Mu Tang
Received on 2001-11-20