views:

55

answers:

2

i need to send a file to a webserver using libcurl. i saw one of the examples in the curl website and am trying to implement it. it is the postit2.c example. can someone tell me how i might extend this to be able to send username and password as well

A: 

Use curl_formadd to add some more fields to the POST data.

If you wanted to add code to that sample you would do in the section where the form is being setup, just above the comment: /* Fill in the submit field too, even if this is rarely needed */.

The code you would add would be something like this:

curl_formadd(&formpost,
             &lastptr,
             CURLFORM_COPYNAME, "user", //the name of the data to send
             CURLFORM_COPYCONTENTS, "username", //the users username
             CURLFORM_END);

curl_formadd(&formpost,
             &lastptr,
             CURLFORM_COPYNAME, "pass", //the name of the data to send
             CURLFORM_COPYCONTENTS, "mypass", //the users password
             CURLFORM_END);

The HTML form to submit the same data (Assuming the user typed in the correct passwords) would look something like this:

Username: <input type="text" name="user" /> <br />
Password: <input type="password" name="pass" />
Yacoby
can you tell me how the send form would look like in html?? i was trying to test this using wireshark but i couldn't see the html code itself.
sfactor
Yacoby
how would i know if the submission is successful in this case from my part?
sfactor
A: 

For example, look 'res = curl_easy_perform(curl);' part in postit2.c...You can add 'printf("CurlCode: %d", res);'. If result is 0, it means that the submission is successfull.

stdio