cURL / Mailing Lists / curl-library / Single Mail

curl-library

how to send POST request when follow location

From: xinyi huang <huangxinyi.cn_at_gmail.com>
Date: Tue, 12 Jul 2011 19:39:58 +0800

I have send a POST request, and set CURLOPT_FOLLOWLOCATION to be TRUE.
The peer http url will location to a new https url.
Output information shows that curl automatically send a new GET request to
the new url.
But what I want is a POST request,cause that is the peer server's design.

How can I get that way? Thanks.

And, here is my code:

    contentFile = "Content.tmp";
    FILE *fContent = fopen(contentFile.c_str(), "w+");
    if (NULL == fContent)
    {
        return ERR;
    }

    CURL * curl = curl_easy_init();
    if (curl == NULL)
    {
        return ERR;
    }

    char error[2048] = {0};
    curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    curl_easy_setopt(curl, CURLOPT_URL, curUrl.c_str());
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); //automatolly jump
   // curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 255);
   /curl_easy_setopt(curl, CURLOPT_WRITEDATA, fContent);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallBack);
    //curl_easy_setopt(curl, CURLOPT_HEADER, 1);
   // curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookieFile.c_str());
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postField.c_str());
    curl_easy_setopt(curl, CURLOPT_POST, 5);

    curlRet = curl_easy_perform(curl);

    if (CURLE_OK == curlRet)
    {
        std::cout<< "success to perform curl. " << endl;
    }
    else
    {
        std::cout<< "fail to perform curl." <<"curlRet:"<<curlRet<< "err:"
<< error << endl;
    }

     curl_easy_cleanup(curl);

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-07-12