Hi all:
I'm trying to interact with a web page with my program.
The situation is:
There are two pages: page1.php and page2.php
In page1.php, there are some codes for a form containing a few text fields and three selections. The text and selected options are going to be posted(method=POST) to page2.php
page2.php display what my program selected.
Okay, I've successfully hook up with page1.php
below is the code I have for the moment:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_URL, "http://www.mysite.com/page1.php");
/* Now specify the POST data */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=h9uest&email=h9uest@h9uest.com&comments=hi");
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
else
{
cerr << "Fail to create curl handle for post method\n";
exit(1);
};
|
Questions:
1,
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=h9uest&email=h9uest@h9uest.com&comments=hi");
doesn't deal with selections. How do I post selection data? assume name is "mychoice".
2, how can I get the response, i.e. page2.php? I want to get the display of page2.php and verify that data did get posted.
for you information, page2.php is written as:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
<?php
echo($_POST['name'] . "\n");
echo($_POST['email'] . "\n");
echo($_POST['comments'] . "\n");
$choices = $_POST['mychoice'];
if(empty($choices))
{
echo("You didn't select any items.");
}
else
{
$N = count($choices);
echo("You selected $N entrie(s): ");
for($i=0; $i < $N; $i++)
{
echo($choices[$i+1] . "\n");
}
}
?>
|
3, how do I download a jpg file in my program? I've already extracted the url of the image I want.
Thank you very much, and I am looking forward to hearing from you!