示例#1
0
        public static string GetJsonFromOAuthUrl(OAuthAccessToken oauthToken, string url)
        {
            var uri    = new Uri(url);
            var webReq = (HttpWebRequest)WebRequest.Create(uri);

            webReq.Accept = MimeTypes.Json;
            if (oauthToken.AccessToken != null)
            {
                webReq.Headers[HttpRequestHeader.Authorization] = OAuthAuthorizer.AuthorizeRequest(
                    oauthToken.OAuthProvider, oauthToken.AccessToken, oauthToken.AccessTokenSecret, HttpMethods.Get, uri, null);
            }

            using (var webRes = webReq.GetResponse())
                return(webRes.ReadToEnd());
        }
示例#2
0
        public static string GetJsonFromOAuthUrl(
            string consumerKey, string consumerSecret,
            string accessToken, string accessTokenSecret,
            string url, string data = null)
        {
            var uri    = new Uri(url);
            var webReq = (HttpWebRequest)WebRequest.Create(uri);

            webReq.Accept = MimeTypes.Json;

            if (accessToken != null)
            {
                webReq.Headers[HttpRequestHeader.Authorization] = OAuthAuthorizer.AuthorizeRequest(
                    consumerKey, consumerSecret, accessToken, accessTokenSecret, HttpMethods.Get, uri, data);
            }

            using var webRes = PclExport.Instance.GetResponse(webReq);
            return(webRes.ReadToEnd());
        }
示例#3
0
        public static string GetJsonFromOAuthUrl(
            string consumerKey, string consumerSecret,
            string accessToken, string accessTokenSecret, 
            string url, string data = null)
        {
            var uri = new Uri(url);
#pragma warning disable CS0618, SYSLIB0014
            var webReq = WebRequest.CreateHttp(uri);
#pragma warning restore CS0618, SYSLIB0014
            webReq.Accept = MimeTypes.Json;

            if (accessToken != null)
            {
                webReq.Headers[HttpRequestHeader.Authorization] = OAuthAuthorizer.AuthorizeRequest(
                    consumerKey, consumerSecret, accessToken, accessTokenSecret, HttpMethods.Get, uri, data);
            }

            using var webRes = PclExport.Instance.GetResponse(webReq);
            return webRes.ReadToEnd();
        }
示例#4
0
        public static async Task <string> GetJsonFromOAuthUrlAsync(
            string consumerKey, string consumerSecret,
            string accessToken, string accessTokenSecret,
            string url, string data = null, CancellationToken token = default)
        {
            var uri    = new Uri(url);
            var webReq = (HttpWebRequest)WebRequest.Create(uri);

            webReq.Accept = MimeTypes.Json;

            if (accessToken != null)
            {
                webReq.Headers[HttpRequestHeader.Authorization] = OAuthAuthorizer.AuthorizeRequest(
                    consumerKey, consumerSecret, accessToken, accessTokenSecret, HttpMethods.Get, uri, data);
            }

            using var webRes = await webReq.GetResponseAsync();

            using var stream = webRes.GetResponseStream();
            return(await stream.ReadToEndAsync(HttpUtils.UseEncoding).ConfigAwait());
        }