windows-phone-8.1win-universal-appwindows-rt

Universal app HttpClient header error


I'm creating universal application and I need to use Keep-Alive connection header for my requests. I have the code

using (var client = new System.Net.Http.HttpClient())
{
    client.DefaultRequestHeaders.Add("connection", "Keep-Alive");
    var str = await client.GetStringAsync(uri);
    return str;
}

but I catch exception The header Connection has an empty value. Please somebody show me where is my mistake and how I can set Connection header to Keep-Alive

I've added screenshot from Wireshark where you can see Connection header value by default (if remove client.DefaultRequestHeaders.Add("connection", "Keep-Alive");)

Connection header by default


Solution

  • Windows.Web.Http.HttpClient requests are Keepp-Alive by default.