Exemple #1
0
        public async Task <OAuthResponse> RequestApiget(string uri, string method, string key)
        {
            NewRequest();
            _params["key"] = key;

            var signature = GetSignature(uri, method);

            _params["oauth_signature"] = signature;

            var authzHeader = $"OAuth {GetAuthorizationHeader(uri, method)}";
            var fullUrl     = $"{uri}?{EncodeRequestParameters(_params)}";

            System.Diagnostics.Debug.WriteLine("\nfullUrl: ");
            System.Diagnostics.Debug.WriteLine(fullUrl);

            var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(fullUrl);

            request.Method = method;
            // request.Headers.Add("Authorization", authzHeader);
            System.Diagnostics.Debug.WriteLine("Authorization: ");
            System.Diagnostics.Debug.WriteLine(authzHeader);

            try
            {
                using (var response = await request.GetResponseAsync())
                {
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {
                        var r = new OAuthResponse(await reader.ReadToEndAsync());
                        return(r);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception(
                          $"Couldn't get ret response stream from fancy hands api. " +
                          $"Method={method} Key={key}", e);
            }
        }