Project

General

Profile

Bad file descriptor error message when posting with Wt::Http::Client

Added by Hans-Michael Muller over 9 years ago

Hello,

I have switched from wt.3.3.2 to wt.3.3.4. Now I receive a 'Bad File Descriptor\" error message when posting something to a server. My code follows the example in the witty documentation. Does anybody know what's going on?

Thanks,

Michael.

void ConfigurableAnnotatorContainer::HandDownToHttpClient(std::string msg) {
    httpdialog_->contents()->clear();
    httpdialog_->contents()->addWidget(new Wt::WText("Waiting for response from server..."));
    Wt::Http::Message message2GO;
    message2GO.setHeader("Content-Type", "text/html; charset=utf-8");
    message2GO.addHeader("User-Agent", "An Application");
    message2GO.addBodyText(msg);
    Wt::Http::Client * client = new Wt::Http::Client(this);
    client->setTimeout(10);
    client->done().connect(boost::bind(&ConfigurableAnnotatorContainer::HandleHttpResponse, this, _1, _2));
    if (!client->post(formurl_, message2GO))
        std::cerr << "Post request in HandDownToHttpClient could not be scheduled." << std::endl;
    else
        Wt::WApplication::instance()->deferRendering();
}

void ConfigurableAnnotatorContainer::HandleHttpResponse(boost::system::error_code err, const Wt::Http::Message & response) {
    Wt::WApplication::instance()->resumeRendering();
    httpdialog_->contents()->clear();
    if (!err) {
        httpdialog_->contents()->addWidget(new Wt::WText("Response from server:"));
        httpdialog_->contents()->addWidget(new Wt::WBreak());
        if (response.status() == 200) {
            std::string aux = response.body();
            boost::regex reg("<.+?>");
            aux = boost::regex_replace(aux, reg, "");
            std::vector<std::string> splits;
            boost::split(splits, aux, boost::is_any_of(","));
            if (!splits.empty()) {
                aux = splits[0];
                if (splits.size() > 1) aux += ",";
                Wt::WText * responsebody = new Wt::WText(aux);
                httpdialog_->contents()->addWidget(responsebody);
                httpdialog_->contents()->addWidget(new Wt::WBreak());
                for (int i = 1; i < splits.size(); i++) {
                    aux = splits[i];
                    if (i < splits.size() - 1) aux += ",";
                    responsebody = new Wt::WText(aux);
                    httpdialog_->contents()->addWidget(responsebody);
                    httpdialog_->contents()->addWidget(new Wt::WBreak());
                }
            }
        } else {
            std::stringstream resp;
            resp << response.status() << " ";
            resp << response.body() << std::endl;
            httpdialog_->contents()->addWidget(new Wt::WText(resp.str()));
        }
    } else {
        std::string aux = "HandleHttpResponse error: " + err.message() + ".";
        httpdialog_->contents()->addWidget(new Wt::WText(aux));
        httpdialog_->contents()->addWidget(new Wt::WBreak());
        aux = "If problem persists, contact abc@def.com.";
        httpdialog_->contents()->addWidget(new Wt::WText(aux));
        Wt::log("error") << "HandleHttpResponse error: " << err.message();
    }
    httpdialog_->contents()->addWidget(new Wt::WBreak());
    Wt::WPushButton * ok = new Wt::WPushButton("Ok", httpdialog_->contents());
    ok->clicked().connect(httpdialog_, &Wt::WDialog::accept);
}

Replies (3)

RE: Bad file descriptor error message when posting with Wt::Http::Client - Added by Jeunn Hao Chong over 9 years ago

I am facing the same problem while posting to Dropbox API. It usually occurs when a request has failed. please see attached an image of the network console.

RE: Bad file descriptor error message when posting with Wt::Http::Client - Added by Jeunn Hao Chong over 9 years ago

Hey Hans,

You might want to try to include '-t 1' in your command line to force it to single thread. It happens to be a threading issue weirdly. Only setting it in Wt_config.xml did not seem to work.

RE: Bad file descriptor error message when posting with Wt::Http::Client - Added by Hans-Michael Muller over 9 years ago

Hi,

thanks for the info. I'll look into it!

Michael.

    (1-3/3)