cURL / Mailing Lists / curl-library / Single Mail


How to send POST form?

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

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="" 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
      <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>
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
   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=

   char *lat_value="41.103731";
   char *lng_value="-73.796341";
   char *url ="";

     // 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",
   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 */
                CURLFORM_COPYNAME, "submit",
                CURLFORM_COPYCONTENTS, "send",

   // 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);

   /* always cleanup */

   /* then cleanup the post chain */

Jung-Mu Tang
Received on 2001-11-20