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

Commented Issue: live_client throw exception from listener [109]

$
0
0
There was an exception from the listener, resulting in " This page can’t be displayed" error in the browser after successful login. Sometimes this exception bubbles up to the client and kills the app

```
static void live_client()
{
oauth2_config live_cfg(s_live_key, s_live_secret,
U("https://login.live.com/oauth20_authorize.srf"),
U("https://login.live.com/oauth20_token.srf"),
U("http://www.livetestdummy.arturl.com:8890/"));
// Scope "wl.basic" allows getting user information.
live_cfg.set_scope(U("wl.basic wl.contacts_photos"));

http_client_config config;
config.set_oauth2(live_cfg);

http_client api(U("https://apis.live.net/v5.0/"), config);

live_cfg.fetch_token(code_from_localhost_listener(live_cfg)).then([&] {
return api.request(methods::GET, U("me/albums?"));
}).then([&](http_response albums) {
return albums.extract_json();
}).then([&](json::value albums) {
auto& obj = albums.as_object();
auto& data = obj[U("data")].as_array();
ucout << "Albums:" << std::endl;
for (auto&x : data)
{
ucout << x.as_object()[U("name")] << std::endl;
}
}).wait();
}
```
Comments: __Fixed__. The new sample version avoids the issue by allocating the http_listener to the heap. Issue was caused by thread synchronization; http_listener was destroyed in the main thread before the reply from the listener thread had been received by the web browser. The http_listener was destroyed prematurely since it was allocated in the stack (as local variable). __Additionally__, while fixing this, I noticed http_request::reply() task does not complete after the reply reaches destination (web browser) - as I had expected - but instead it completes earlier. As a result I could not use the reply() task to synchronize the destruction of the http_listener.

Viewing all articles
Browse latest Browse all 4845

Trending Articles