curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Curl vs libcurl

From: Brian Meekings via curl-library <>
Date: Wed, 20 Oct 2021 10:38:23 +0100

I'm experiencing different results with an http GET request between command
line curl and an application using libcurl.

Using command line curl verbosely I get:
* Connected to ( port 80 (#0)
> GET /index.php?nav=objectq_simClient_c HTTP/1.1^M
> User-Agent: curl/7.29.0^M
> Host:^M
> Accept: */*^M
> ^M
< HTTP/1.1 200 OK^M
< Server: openresty/^M
< Date: Tue, 19 Oct 2021 15:13:03 GMT^M
< Content-Type: text/html^M
< Transfer-Encoding: chunked^M
< Connection: keep-alive^M
< Vary: Accept-Encoding^M
< X-Powered-By: PHP/5.4.45^M
< Expires: Thu, 19 Nov 1981 08:52:00 GMT^M
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
< Pragma: no-cache^M
< Set-Cookie: PHPSESSID=16e4632a646dab684ec886c8127e804b; path=/^M
< X-Webcom-Cache-Status: BYPASS^M
< ^M
{ [data not shown]
                <title>Information Design, Inc.</title>

But from the application I get:
    cpUtility.c:509: curl: <Connected to
( port 80 (#0)>
    cpUtility.c:494: => Send header<GET /index.php?nav=objectq_simClient_c
Accept: */*^M
    cpUtility.c:494: <= Recv header<HTTP/1.1 400 Bad Request^M>
    cpUtility.c:494: <= Recv header<Server: openresty/^M>
    cpUtility.c:494: <= Recv header<Date: Tue, 19 Oct 2021 15:08:15 GMT^M>
    cpUtility.c:494: <= Recv header<Content-Type: text/html^M>
    cpUtility.c:494: <= Recv header<Content-Length: 163^M>
    cpUtility.c:494: <= Recv header<Connection: keep-alive^M>
    cpUtility.c:494: <= Recv header<^M>
    cpUtility.c:494: <= Recv data<<html>^M
<head><title>400 Bad Request</title></head>^M
<center><h1>400 Bad Request</h1></center>^M
    cpUtility.c:479: WriteMemoryCallback: 163 bytes read
    cpUtility.c:508: curl: 56 bytes
    cpUtility.c:509: curl: <Connection #0 to host
left intact>
    cpUtility.c:585: 163 bytes received
    cpUtility.c:598: Line read: <html>^M
    cpUtility.c:598: Line read: <head><title>400 Bad
    cpUtility.c:598: Line read: <body>^M
    cpUtility.c:598: Line read: <center><h1>400 Bad Request</h1></center>^M
    cpUtility.c:598: Line read: <hr><center>openresty/</center>^M
    cpUtility.c:598: Line read: </body>^M
    cpUtility.c:598: Line read: </html>^M

The application code looks like:
        curl = curl_easy_init();
        if(curl) {
                CURLcode res;

                // Set the URL
                curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
                // Send all data to this function
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
                // We pass our 'chunk' to the callback function
                curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
                // Disable authentication
                curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
                // Debuggging aid
                curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
                curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, traceCurl);

                // Get the file
                res = curl_easy_perform(curl);

The GET request looks the same in both to me, so why does one succeed, and
the other fail? I'd really appreciate it if anyone can shed any light on

Received on 2021-10-20