Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 890231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:41:53+00:00 2026-05-15T13:41:53+00:00

This issue/quirk/side-effect is driving me crazy. Near the bottom the code, the response code

  • 0

This issue/quirk/side-effect is driving me crazy. Near the bottom the code, the response code of the HTTP interaction is passed by reference into responseCode_. However it often comes out as 0 even though the site can otherwise be accessed, and returns too quickly to be a timeout…

All variables are defined, the code below is just a snippet of a C++ method in a class. Any var_ variables are instance based. It runs on several threads, but that should not be a problem. Each class that uses libcurl has its own instance on the respective threads.

Thanks in advance for any ideas or advice…

 CURL *curl;
 curl = curl_easy_init();
 //The URL
 curl_easy_setopt(curl, CURLOPT_URL, url.getURLString().c_str());
 //Timeout
 curl_easy_setopt(curl, CURLOPT_TIMEOUT, &timeout_);
 //disable signals to use with threads
 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
 //Redirecting
 curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5);
 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
 //Writing callback
 curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, &writerh);
 curl_easy_setopt(curl, CURLOPT_HEADERDATA, &head_);
 //Writing callback
 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writerb);
 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &body_);
 //Headers
 struct curl_slist *headers = NULL;
 for (std::map<std::string, std::string>::iterator itr = requestHeaders_.begin(); itr != requestHeaders_.end(); itr++) {
  std::stringstream header;
  header << itr->first << ": " << itr->second;
  headers = curl_slist_append(headers, header.str().c_str());
 }
 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
 //UA
 curl_easy_setopt(curl, CURLOPT_USERAGENT, "RDFaS-Bot/1.0 (+http://www.rdfas.com/bot)");
 curl_easy_perform(curl); /* ignores error */
 //Response code
 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responseCode_);
 //clean headers
 curl_slist_free_all(headers);
 curl_easy_cleanup(curl);

Update:

curl_easy_perform was not returning CURLE_OK when the response code was 0, as the marked answer explains. However debug hooks are very useful too and an excellent suggestion

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:41:54+00:00Added an answer on May 15, 2026 at 1:41 pm

    The response code is only going to be set if curl_easy_perform() returns CURLE_OK so you should check that first to make sure curl actually performed the request successfully. Are you sure the callback functions for writing the header and body are set up correctly?

    Also, make sure curl_global_init(CURL_GLOBAL_ALL) is called before these easy_perform threads start.

    Assuming nothing in the curl handle returned by curl_easy_init() is shared across threads, then the code looks correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 510k
  • Answers 510k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The server where it doesn't work is sending the CSS… May 16, 2026 at 5:02 pm
  • Editorial Team
    Editorial Team added an answer Unregister your receiver May 16, 2026 at 5:02 pm
  • Editorial Team
    Editorial Team added an answer The string does not contain the backslashes. Only the debugger… May 16, 2026 at 5:02 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

This issue stems from an accounting package that spits out text-based reports with rows
there's this issue with JSTL I'm stuck with for the past couple of days.
I have a ul/li based side menu, styled with two CSS rules, the following
I am writing a client-side Swing application (graphical font designer) on Java 5 .
While I have seen this question asked, I haven't seen the answer. I just
I have this SphereInFrustrum function here: 0.49% int FrustumG::sphereInFrustum(Vec3 &p, float radius) { int
I'm doing the Agile Yii book. Anyway, I'm trying to execute this command: INSERT
I am currently playing around with the Asp.Net mvc framework and loving it compared
In a web application, I'm hitting some troubles with dynamic content - whereby a
One of the many quirks of Reporting Services we've run across is the complete

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.