Cookie

May 7, 2013 at 2:28 PM
Hi everyone,
How to use cookies with casablanca ?

I've made the following code.
IAsyncOperation<String^>^ Component42::GetHttpAsync(String^ absoluteUri, String^ parameters)
{
    //auto myUri = uri( L"http://localhost:57473/api/values");  FOR TESTING
    
    wstring strAbsoluteUri ( absoluteUri->Data() );
    wstring strParameters ( parameters->Data() );
    
    http_client_config config();
    http_client client( strAbsoluteUri );
    auto op = pplx::create_async([&client, strParameters]() 
    {
        return client.request(methods::GET, strParameters)
            .then([](pplx::task<http_response> tsk) -> Platform::String^
            {
                auto response = tsk.get();
                return ref new Platform::String(response.extract_string().get().c_str());
            });
    });
    
    return op;
}
May 16, 2013 at 3:40 PM
Sorry, cookie support is currently not in the Casablanca APIs. I know, it seems pretty basic...

That said, cookies are passed as headers (in both directions), and you should be able to handled them yourself by examining the headers of incoming responses and setting headers of outgoing requests. Instead of calling request() with the method and request uri directly, you will need to create a http_request object, add the set-cookie header, and use the request() overload that takes a http_request instance.

I believe RFC 2109 should provide all the information you need.

Niklas