User Input into HTTP

Aug 7, 2014 at 7:15 PM
Edited Aug 7, 2014 at 7:46 PM
As I'm building an HTTP request, is there any way to prompt the user in the command window for the server/port/path etc.?

Something like:
string DummyURI
cout << "Enter protocol and server:  " << endl;
cin >> DummyURI

web::uri_builder uribuilder(DummyURI);
auto uri = uribuilder.to_uri();
http_client client(uri);
client.request(methods::GET).then([](http_response response)
{});
where the user would enter:

http://www.google.com

or something like that into the command window


Can anyone think of a simple way to do that?
Coordinator
Aug 11, 2014 at 9:02 PM
H mrm63,

Maybe I'm misunderstanding something here, but why can't you just us std::cin if this is a simple command line application? The following works just fine for me:
    std::string DummyURI;
    std::cout << "Enter protocol and server:  " << std::endl;
    std::cin >> DummyURI;
    std::cout << "Entered URI:" << DummyURI << std::endl;

    web::uri_builder uribuilder(utility::conversions::to_string_t(DummyURI));
    auto uri = uribuilder.to_uri();
    // Use with http_client...
Steve
Aug 25, 2014 at 6:42 PM
Edited Aug 26, 2014 at 3:46 PM
Hi Steve,

Thanks for that! I'm very close, but am still having some unresolved external symbol errors with the DummyURI string.

As it stands, my code looks like this:
    std::string DummyURI;
    std::cout << "Enter protocol and server:  " << std::endl;
    std::cin >> DummyURI;
    std::cout << "Entered URI:" << DummyURI << std::endl;
and:
void LabelMaker(int number)
{
    web::uri_builder uribuilder(utility::conversions::to_string_t(DummyURI));
    uribuilder.append_path(L"api/");
    uribuilder.append_query(L"Function", L"OverlayInput1");
    uribuilder.append_query(L"Input", number);
    auto uri = uribuilder.to_uri();
    http_client client(uri);
    client.request(methods::GET).then([](http_response response)
    {});
}
where these two blocks of code are in two separate cpp files in a Visual studio project using DummyURI as an external variable.
Is there a problem with my syntax that you can see? or do I maybe need to take "DummyURI" as a string input into the function as well, or something else that anyone else might see?

Basically what I need is for the user to be able to enter an IP address and port number such as "http://10.150.60.121:8808" and then the function adds on the path & query, and then uses http client.

Thanks in advance, really appreciate the help!
Coordinator
Aug 26, 2014 at 4:55 PM
Hi mrm63,

It sounds like you don't have the variable used in a way that can be shared across your two cpp sources files. You either need to use a header file or use extern on the variable. FYI this doesn't actually have anything to do with the C++ Rest SDK.

Steve
Aug 27, 2014 at 3:53 PM
Hi Steve,

Apologies, I know it's not related to C++ Rest SDK--So is my syntax was correct in the "LabelMaker" function??

Thanks,
Matt
Coordinator
Aug 27, 2014 at 4:23 PM
Hi Matt,

At a quick glance the usage of uri_builder looks OK, obviously you aren't doing anything with the http_response. Now you just need to make sure to setup your extern variables correctly.

Steve