HttpClient does not send the same request to W10 UAP

Currently, I am facing what, in my opinion, is a bug in the System.Net.Http library and its class HttpClient. Please note that I am using HttpClientfrom a portable class library.

If I am a user the HttpClient.SendAsyncfollowing query: https://api.twitter.com/1.1/search/tweets.json?q=%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82 % 21 & result_type = mixed & count = 100 , the request made by .NET is different if it is running in UAP and if it is running in a console application. (query = Hello! )

I was able to identify this through Fiddler:

Console Application:

GET https://api.twitter.com/1.1/search/tweets.json?q=%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82!&result_type=mixed&count= 100 HTTP / 1.1

User Agent: Tweetinvi / 0.9.11.1

Cache-control: no-cache

Authorization: OAuth oauth_consumer_key = "jjMV4k3n9EswD9hlhRZqQCZrm", oauth_nonce = "222222", oauth_signature_method = "HMAC-SHA1", oauth_timestamp = "1458086400", oauth_token = "1693649419-BlEivyWIiOVrb22JjdzRipXWp4ltVdo4VLye1VW", oauth_version = "1.0", oauth_signature = "ODaUZNfxMbM7l0gtZ1GEFsjr% 2BAA% 3D "

Host: api.twitter.com

Connection: Keep-Alive

Universal Windows 10 application:

GET https://api.twitter.com/1.1/search/tweets.json?q=%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%21&result_type=mixed&count= 100 HTTP / 1.1

Cache-control: no-cache

User Agent: Tweetinvi / 0.9.11.1

Authorization: OAuth oauth_consumer_key = "jjMV4k3n9EswD9hlhRZqQCZrm", oauth_nonce = "222222", oauth_signature_method = "HMAC-SHA1", oauth_timestamp = "1458086400", oauth_token = "1693649419-BlEivyWIiOVrb22JjdzRipXWp4ltVdo4VLye1VW", oauth_version = "1.0", oauth_signature = "ODaUZNfxMbM7l0gtZ1GEFsjr% 2BAA% 3D "

Host: api.twitter.com

Connection: Keep-Alive

Cookie: guest_id = v1% 3A145704170375190067

, , % 82! ( ).

, W10 % 82% 21. HTML-.

, W10 cookie.

.NET Framework/HttpClient?

, SAME HttpClient.SendAsync, ( ).

:

public class HttpClientWebHelper : IHttpClientWebHelper
{
    public async Task<HttpResponseMessage> GetHttpResponse(ITwitterQuery twitterQuery, HttpContent httpContent = null, ITwitterClientHandler handler = null)
    {
        using (var client = GetHttpClient(twitterQuery, handler))
        {
            client.Timeout = twitterQuery.Timeout;

            var httpMethod = new HttpMethod(twitterQuery.HttpMethod.ToString());

            if (httpContent == null)
            {
                return await client.SendAsync(new HttpRequestMessage(httpMethod, twitterQuery.QueryURL)).ConfigureAwait(false);
            }
            else
            {
                if (httpMethod != HttpMethod.Post)
                {
                    throw new ArgumentException("Cannot send HttpContent in a WebRequest that is not POST.");
                }

                return await client.PostAsync(twitterQuery.QueryURL, httpContent).ConfigureAwait(false);
            }
        }
    }

    public HttpClient GetHttpClient(ITwitterQuery twitterQuery, ITwitterClientHandler twitterHandler = null)
    {
        var handler = (twitterHandler as TwitterClientHandler) ?? new TwitterClientHandler();
        handler.TwitterQuery = twitterQuery;

        var client = new HttpClient(handler)
        {
            Timeout = twitterQuery.Timeout,
        };

        return client;
    }
}
+4

All Articles