1

I use C++ REST SDK to build up a HTTP server which is used for receiving requests from postman, but if I code like this:

http_listener listener(L"http://localhost/io");
listener.open().wait();

listener.support(methods::POST, [](http_request req) {
 });

Postman can connect to it with http://localhost/io in POST method, But if I code like :

http_listener listener(L"http://localhost:6000/io");

Postman cannot connect to it with http://localhost:6000/io and POST method. But if I code like http_listener listener(L"http://localhost/io:6000"); Postman can connect with it in http://localhost/io:6000 with POST method. How could I make http://localhost:6000/io works for my listener ? Another program I work with always send http request to http://localhost:6000/io, so I need to let my server listen on this address.

http_listener listener(L"http://localhost:6000"); //doesn't work, too.

But when I change 6000 to any other port num,like 7000 or 8000, like http_listener listener(L"http://localhost:7000") or http_listener listener(L"http://localhost:7000/io") it works for me. I use netstat -a -b to check whether 6000 has been occupied by another program, but 6000 is free.

firstaccount
  • 155
  • 2
  • 13
  • 1
    I believe `"http://localhost/iotresponse:6000"` is connecting to port 80 (the default) and not 6000. – Pawel Oct 06 '16 at 21:38
  • @Pawel how about "http://localhost:6000/iotresponse"? Does it also connect to port 80 ? The requirement for me is listening on "http://localhost:6000/iotresponse" – firstaccount Oct 06 '16 at 22:08
  • No, `http_listener(L"localhost:6000")` should listen on port 6000. I don't know why port 6000 does not work while other ports do work. I thought it was because something else was using port 6000 but you said that netstat did not show that port 6000 was taken so I don't know... – Pawel Oct 06 '16 at 22:32

1 Answers1

0

I think I have the answer. I went through this same problem and I used a différent unused port and a different use of "support" function :

http_listener listener(L"http://localhost:11369/");
listener->open().wait();
listener->configuration() ;

listener->support(methods::GET,
        std::tr1::bind(&CMFCApplication1Dlg::handle_get,
            this,
            std::tr1::placeholders::_1));
listener->support(methods::PUT,
        std::tr1::bind(&CMFCApplication1Dlg::handle_put,
            this,
            std::tr1::placeholders::_1));
listener->support(methods::POST,
        std::tr1::bind(&CMFCApplication1Dlg::handle_post,
            this,
            std::tr1::placeholders::_1));
listener->support(methods::DEL,
        std::tr1::bind(&CMFCApplication1Dlg::handle_delete,
            this,
            std::tr1::placeholders::_1));

I use http_listener in a C++ MFC app. So it will be surely different for you. If you need any help for the handlers to answer to the received requests don't hesitate to tell me! Sincerely, Ahmed.