Search code examples
c++httpchilkat

chilkat CkHttp c++ : need Content-Length=0 using PUT and DELETE verbs


I'm using Chilkat 9.5.0.75 x86-vc10-sp1 ( and tested on 9.5.0.76 too ). I need to use a webservice that requires Content-Length specified also for PUT and DELETE calls with empty body. I read this http://www.chilkatforum.com/questions/5485/need-content-length0-http-header-even-when-message-is-empty/5528 from the old forum, but I still have the issue. Is there any workaround ? This is the way I make the PUT call

CkHttp http;
if (!http.UnlockComponent(CK_UNLOCKCODE)) return false;
http.put_SessionLogFilename("http.txt");
http.AddQuickHeader("X-Authorization", authToken);
http.AddQuickHeader("Accept", "application/json");

CkString os;
http.QuickPutStr(endpoint, os);
int res = http.get_LastStatus();

Thank you for any advice


Solution

  • AddQuickHeader is deprecated, use SetRequestHeader instead.

    If you explicitly set the Content-Length to 0, it should result in the "Content-Length: 0" header being added to the request.

    
        http.SetRequestHeader("Content-Length","0");
    
    

    Normally you would never explicitly set the Content-Length header because Chilkat automatically adds it (if non-zero) based on the actual content length.