2

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);
marcks
  • 400
  • 1
  • 2
  • 11
  • Check out the c++ HTTP https://stackoverflow.com/questions/1011339/how-do-you-make-a-http-request-with-c – usmanfarooq Mar 15 '20 at 08:49
  • Check the end point on the server is actually working. Check the port number. Your code looks correct, except you need to call `session.receiveResponse()` to get the response after `sendRequest()`. – jignatius Mar 15 '20 at 09:24
  • @jignatius Thanks for replying. The receiveResponse follows later in my code. I did not include it because the exception was thrown before. Seems like the problem is that you can no longer use "localhost" as an alias for "127.0.0.1". I have added an answer to this question regarding this. – marcks Mar 15 '20 at 09:31

1 Answers1

2

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.

marcks
  • 400
  • 1
  • 2
  • 11