Simple http_client example fails on VS10

Locked Simple http_client example fails on VS10

  • Tuesday, May 22, 2012 2:35 PM
     
      Has Code

    Hi,

    I have

        try 
        {
            http::client::http_client client(L"http://www.google.com");
            auto response = client.request(http::methods::GET, L"index.html");
            response.then([=](pplx::task<http_response> task)
            {
                try 
                {
                     client::http_response response = task.get(); //get exception here
                     auto body = response.body();
                }
                catch(std::exception& ex)
                {
                }
            });
        }
        catch(std::exception& ex)
        {
        }

    I get an exception when getting http_response. It's not clear for me what are the arguments to the http_client constructor I think.

    I use VS10SP1 and looking over the samples that come with libraries (and copying casablanca100.dll to be used by the app) I included the needed library dependencies.


All Replies

  • Tuesday, May 22, 2012 5:45 PM
     
      Has Code

    The argument to the http_client constructor specifies the base URI to be used for all requests. Then any path (possibly including a query or fragment as well) specified in client.request(...) is appended to the base URI. We choose to do this to make it convenient to not have to specify the URI repeatedly with each request. So in your code above the request URI is http://www.google.com/index.html.

    I tried the code you posted out on my Windows 7 machine successfully received a 200 "OK" response with the correct information. Can you examine what the exception message is. It should give some indication about why the request failed. Try adding the following code to your catch block and let me know what you get:

        printf("Exception:%s", ex.what());

    Thanks, Steve

  • Wednesday, May 23, 2012 1:01 PM
     
     
    I get "The server name or address could not be resolved". Possibly a DNS issue, but the request works when using IE browser.