Lesson Thirteen curl Content-Length adding mechanism

Scene Description

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Length Required</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Length Required</h2>
<hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>
</BODY></HTML>


analysis

    Description packets sent does not carry the Content-Length, but the message sent by the entity actually is 0 bytes


the reason

    libcurl library only call curl_easy_setopt (pCurlHandle, CURLOPT_POSTFIELDS, "") ;, will go automatically generated Content-Length


Solution to manually specify a Content-Length pCurlHeadList = curl_slist_append (pCurlHeadList, "Content-length: 0");

Solution two  curl_easy_setopt (pCurlHandle, CURLOPT_POSTFIELDS, "" );

    

Guess you like

Origin blog.51cto.com/fengyuzaitu/2427786