I have the following function http_send_message() wich I use each time I want to send a http message:
http_send_message(char *msg_out, char **msg_in)
{
CURLcode res;
CURL *curl;
curl = curl_easy_init();
if (!curl) return -1;
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.133:8080/tawtaw");
curl_easy_setopt(curl, CURLOPT_USERNAME, "tawtaw");
curl_easy_setopt(curl, CURLOPT_PASSWORD, "tawtaw");
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC|CURLAUTH_DIGEST);
.
.
.
curl_easy_cleanup(curl);
}
But I remarked in each time the function send the http message, it try to send a request without the digest authentication header and then it send it with the digest authentication header. In normal case It should do this behaviour only in the first message. And for the subsequent messages it should remeber the authentication header and send it in each message
To obtain such a behavior you need to re-use you curl handle for the subsequent calls to take full advantage of persistent connections and Digest Access Authentication request counter:
In practice do not clean up your curl handle. Instead maintain it and as soon as you need to perform another request:
curl_easy_reset(curl);If you use the
CURLOPT_VERBOSEoption you will see that for the subsequent requests you will have anAuthorizationheader with an increasing request counter (nc=00000002,nc=00000003, etc).