libcurl curl_easy_perform reports “Couldn’t resolve host name” (code 6)

I am getting this error deterministically every time I run the code when I am able to successfully query the site Postman and even using the binary curl command that is a result of the manual libcurl build described below.

This is the curl command that I am using (I am using <my.website> in place of the actual host and in place of the actual correct token):

PS> cd C:curl-8.8.0buildslibcurl-vc-x86-release-static-ipv6-sspi-schannelbin
PS> ./curl --header "Authorization: Bearer <token>" https://<my.website>/api/test

… and I am getting back the expected:

Hello back

However, when I try the same in my C++ x86 project in Visual Studio 2022 like this:

#include <curl/curl.h>
#include <iostream>

void test(CURL* curl) {

    // setup
    const char* url = "https://<my.website>/api/test";
    curl_easy_setopt(curl, CURLOPT_URL, url);
    struct curl_slist* headers = NULL;
    headers = curl_slist_append(headers, "Authorization: Bearer <token>");
    setres = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);

    // request
    CURLcode res;
    res = curl_easy_perform(curl);
    std::cerr << "RESULT: " << res << std::endl;

    // request result checking
    if (res != CURLE_OK) {
        std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;
    } else {
        std::cout << "POST request sent successfully!" << std::endl;
    }

    // cleanup
    curl_slist_free_all(headers);
    curl_easy_cleanup(curl);
}


int main() {

    // global initialization
    CURL * curl;
    curl_global_init(CURL_GLOBAL_SSL);

    curl = curl_easy_init();
    if (curl) {
        test(curl);
    } else {
        std::cerr << "INIT FAILED" << std::endl;
    }

    // global cleanup
    curl_global_cleanup();
}

… I get the following output:

* getaddrinfo() thread failed to start
* Could not resolve host: <my.website>
* Closing connection
RESULT: 6
curl_easy_perform() failed: Couldn't resolve host name

(the <my.website> is again just a placeholder; the real output contains the actual website, of course)

This problem appears immediately with basically zero waiting time (non-zero waiting times may indicate DNS problems acccording to some answers I found).

I have built libcurl “8.8.0 Schannel WinIDN” on my Windows 11 in a x86 mode (using Developer Command Prompt for VS 2022). This created the C:curl-8.8.0buildslibcurl-vc-x86-release-static-ipv6-sspi-schannel with the include, lib and bin subdirectories.

My project is constructed as a x86 project with the following options in properties:

C/C++ / General / Additional Include Directories: C:curl-8.8.0buildslibcurl-vc-x86-release-static-ipv6-sspi-schannelinclude
C/C++ / Preprocessor / Preprocessor Definitions: CURL_STATICLIB;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
Linker / General / Additional Library Directories: C:curl-8.8.0buildslibcurl-vc-x86-release-static-ipv6-sspi-schannellib
Linker / Input / Additional Dependencies: libcurl_a.lib;Ws2_32.lib;Wldap32.lib;Crypt32.lib;Normaliz.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)

While trying to figure out what’s wrong, I have read this post getaddrinfo thread failed to start #6495 which recommended to execute also the following:

    curl_version_info_data* ver = curl_version_info(CURLVERSION_NOW);
    std::cerr << "VERSION: " << curl_version() << std::endl;
    if (!(ver->features & CURL_VERSION_ASYNCHDNS)) {
        std::cerr << "SYNCHRONOUS" << std::endl;
    } else if (!ver->age || ver->ares_num) {
        std::cerr << "ARES" << std::endl;
    } else {
        std::cerr << "THREADED" << std::endl;
    }

… which outputs:

VERSION: libcurl/8.8.0 Schannel WinIDN
THREADED

Which is what I would expect.

Can someone please tell me what I am doing wrong?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật