Libcurl part of the summary | | Between the Curlopt_postfields with & interval
Source: Internet
Author: User
The Curlopt_postfields is separated by A & interval.
--------the following for the summary of Chinaunix liu277325073, thanks to the--------------Curl is open source things, mainly for the page to download and upload 1, for the page jump site, it is best to use the sniffer of the HTTP packet all grasp the first , analyze the protocol header, especially the URL after post, and remember the session_id in the cookie (the situation varies according to each website). 2, curl_easy_setopt (curl,curlopt_post,1); Using Post mode 3, curl_easy_setopt (curl,curlopt_postfields,buffer) buffer corresponds to content in the contents, similar to "name=zhangsan&pwd=1234 &submit2=%b5%c7+%c2%bc&oriurl=%2f&flag=0 ". 4, Res=curl_easy_setopt (Curl,curlopt_cookiefile, ""); Note Cookies to memory, you can jump in the future without setting the cookie content (according to the site design differences) curl_easy_setopt (CURL,CURLOPT_URL,HOST+POSTURL1)//First address 5, Curl_easy _perform (curl); 6, Curl_easy_getinfo (Curl,curlinfo_response_code,&infocode); 7, through to the return code, ready to jump 8, curl_easy_setopt (CURL,CURLOPT_URL,HOST+URL2) New jump page address 9, curl_easy_perform (curl); Note that the host is the site service URL, followed by the PostURL for the actual requested relative address. The simplest example: #include <stdio.h>;
#include <curl/curl.h>;
#include <stdlib.h>;
int main (int argc, char *argv[])
{
CURL *curl; To define a pointer to a curl type
Curlcode Res; To define a variable of type Curlcode
if (argc!=2)
{
printf ("Usage:file <url>;\n");
Exit (1);
}
Curl = Curl_easy_init (); Initializes a pointer to a curl type
if (curl!=null)
{
Set the Curl option. Where Curlopt_url is to have the user specify the URL. ARGV[1] The URL that is stored in the command line in the
Curl_easy_setopt (Curl, Curlopt_url, argv[1]);
Call Curl_easy_perform to execute our settings. And do the related operations. It's only shown here on the screen.
res = curl_easy_perform (curl);
Clears the curl operation.
Curl_easy_cleanup (curl);
}
return 0;
Note: There is a lot of information on the official website
http://curl.haxx.se/libcurl/
tutorials, manuals, examples, everything.
In addition, the output to the screen is the default action of Libcurl, if you want to change, you can look at the following several connections:
Http://curl.haxx.se/libcurl/c/cu ... tml#curloptreaddata
Http://curl.haxx.se/libcurl/c/cu ... Curloptreadfunction
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.