How to add title in HttpWebRequest in windows8 application?

I am developing a C # \ XAML metro-ui application. I want to call some service and use for this HttpWebRequest. The previous implementation HttpWebRequestcontains the properties ContentLengthand UserAgent. But the implementation for WinRT does not have this. I tried using the approach described in this post. It works for UserAgent, but not for ContentLength. I tried to installHeaders

request.Headers["Content-length"] = Length;
request.Headers["User-agent"] = UserAgent;

But the exception received. The header "Content-length" must be changed using the appropriate property or method. "

Hot can be installed Headersin HttpWebRequest, implemented in WinRT?

+5
source share
1 answer

HttpWebRequest WinRT. , .NET, .

, HttpClient HttpWebRequest API async.

Content-Length, , POST PUT - . PostAsync() PutAsync(), .

    var req = new HttpClient();
    req.DefaultRequestHeaders.Add("User-agent", UserAgent);
    req.DefaultRequestHeaders.Add("Content-length", Length);
    return await req.PostAsync(RequestURL, Body);

, Content-length, , .

+12

All Articles