小编Som*_*Guy的帖子

LibCurl CURLOPT_URL不接受字符串?C++

基本上我想要做的是使用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)

c++ syntax-error libcurl

4
推荐指数
1
解决办法
2392
查看次数

标签 统计

c++ ×1

libcurl ×1

syntax-error ×1