Inputting a string

Oct 7, 2014 at 10:41 AM
Edited Oct 7, 2014 at 12:53 PM
I use this code to place GET request from a listenar application to a webpage, from a listenar command line console application
uri_builder uri(L"http://localhost:2001/");
  listener.support(methods::GET, [](http_request req)
    {
        std::cout << "Serving GET" << std::endl;
    req.reply(status_codes::OK, U("Casablanca SDK!"), U("text/html"));
    });
Just like the way when I run this application, and browse this http://localhost:2001/, it will display "Casablanca SDK!" in the webpage. How can I make this thing dynamic, where I take an input from the user in the command line and it displays this on the webpage?
Oct 7, 2014 at 5:31 PM
Hi maverick786us,

If you are starting your listener from the command line locally you could pass in command line arguments. Then simply supply the string command line arguments to the http_request::reply(...) function. Replace the "Casablanca SDK!" string with what the user entered. Another option is you could read from std::cin.

Steve
Oct 9, 2014 at 5:45 AM
stevetgates wrote:
Hi maverick786us,

If you are starting your listener from the command line locally you could pass in command line arguments. Then simply supply the string command line arguments to the http_request::reply(...) function. Replace the "Casablanca SDK!" string with what the user entered. Another option is you could read from std::cin.

Steve
Can you show me an example? I am new to Lambada programming, can you show me an example where a user inputs something, and then that value is passed in GET Request, without exiting the application?
Oct 9, 2014 at 5:22 PM
You will need to use some external event or mechanism to decide when to actually stop and close your listener. I don't know how you want to decide to do it. Maybe if the user enters a certain command line argument? Or if the listener received a specific request. Supplying a string to the http_request::reply is the same as with the http_client::request(...) API that you've already done, so I don't think it should be difficult.

Steve