基本上我想要做的是使用libcurl来获取稍微不同的URL,例如:
http://foo.com/foo.asp?name=*NAMEHERE*
Run Code Online (Sandbox Code Playgroud)
我想做的是遍历名称向量并获取每个名称,例如:
http://foo.com/foo.asp?name=James
Run Code Online (Sandbox Code Playgroud)
然后
http://foo.com/foo.asp?name=Andrew
Run Code Online (Sandbox Code Playgroud)
等等.
但是,当我尝试这样做时:
int foo (){
CURL *curl;
CURLcode success;
char errbuf[CURL_ERROR_SIZE];
int m_timeout = 15;
if ((curl = curl_easy_init()) == NULL) {
perror("curl_easy_init");
return 1;
}
std::vector<std::string> names;
names.push_back("James");
names.push_back("Andrew");
for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i){
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, long(m_timeout));
curl_easy_setopt(curl, CURLOPT_URL, "http://foo.com/foo.asp?name=" + *i);
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookies.txt");
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookies.txt");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1L);
}
if ((success = curl_easy_perform(curl)) != 0) {
fprintf(stderr, …Run Code Online (Sandbox Code Playgroud)