简体   繁体   中英

Timeout sending HTTPRequest in poco 1.10.1

I have a c++ application that connects to a http server on localhost. The application is running on windows 10. I used to use poco 1.7.8p3 to manage the connection. The library was built with the Visual Studio 15 using the buildwin script shipped with the source and everything has been working fine.

I decided to upgrade poco to version 1.10.1. This time I built the library using CMake.

The code that used to work with version 1.7.8p3 does no longer work with poco 1.10.1. When sending a HTTPRequest from a HTTPClientSession, I get a Poco::TimeoutException. The server never receives the request. Any help solving this problem would be appreciated. Sample code follows below.

HTTPClientSession session

session.setKeepAlive(false);
session.setTimeout(Poco::Timespan(0, 0, 0, 5, 0));

int port = 62300;
session.setPort(port);
session.setHost("localhost");

const std::string uri = "/get_server_config";

HTTPRequest request(HTTPRequest::HTTP_GET, uri, HTTPMessage::HTTP_1_1);

//Generates Poco::TimeoutException
session.sendRequest(request);

auto &sock = session.socket();
const Poco::Timespan ts(10L, 1L);
sock.setReceiveTimeout(ts);

It seems like it is no longer possible to specify the host as "localhost". Changing session.setHost("localhost"); to session.setHost("127.0.0.1"); solved the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM