Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

New Post: Simple example, of documentation to access http server with basic authentication

$
0
0
Hello,

I'm trying to download a file from a server that uses username and password to limit access to its resources.

I've reviewed the examples for Facebook and Windows live, but I think that they are not applicable to a "normal" website

Using the web browser the process is:
1) Welcome page: enter username and password
2) Download the file

Can I do the same using Casablanca?, can you please give me an example?. Currently I received and error code 401 when I run this code:
int _tmain(int argc, _TCHAR* argv[])
{
    auto fileName = L"D:\\sample.xml";

    web::http::uri_builder uribuilder(L"https://mercurial.maptek.com/branch");
    http_client_config config;
    config.set_credentials(credentials(L"user", L"password"));
    
    http_client client(uribuilder.to_uri(), config);

    client.request(methods::GET).then([=](http_response response){
        return response.body();
    }).then([=](streams::istream is){
       streams::streambuf<uint8_t> rwbuf = file_buffer<uint8_t>::open(fileName).get();
        is.read_to_end(rwbuf).get();
        rwbuf.close();
    }).wait();

    return 0;
}
Thanks!

Viewing all articles
Browse latest Browse all 4845


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>