/// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="stream"></param>
        /// <returns></returns>
        public Task <HttpWebResponse> GetHttpWebResponseAsync(String url, Stream stream)
        {
            var cm = new HttpRequestCommand(url);

            cm.SetBodyStream(stream);
            return(this.GetHttpWebResponseAsync(cm));
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public String GetBodyText(HttpRequestCommand command)
        {
            var          res = this.GetHttpWebResponse(command);
            StreamReader sr  = new StreamReader(res.GetResponseStream(), this.ResponseEncoding);

            return(sr.ReadToEnd());
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public HttpWebResponse GetHttpWebResponse(HttpRequestCommand command)
        {
            HttpWebRequest     req = this.CreateRequest(command);
            StreamWriteContext scx = null;

            if (command.BodyStream != null && command.IsSendBodyStream == true)
            {
                //Request body
                //req.ContentLength = command.BodyStream.Length;
                if (command.BodyStream.Length > 0)
                {
                    using (var stm = req.GetRequestStream())
                    {
                        if (this.RequestBufferSize.HasValue == true)
                        {
                            scx = new StreamWriteContext(stm, this.RequestBufferSize.Value);
                        }
                        else
                        {
                            scx = new StreamWriteContext(stm);
                        }
                        scx.Uploading += (o, e) => this.OnUploading(e);
                        scx.Write(command.BodyStream);
                        stm.Dispose();
                    }
                }
            }
            return(req.GetResponse() as HttpWebResponse);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="stream"></param>
        /// <returns></returns>
        public Task <String> GetBodyTextAsync(String url, Stream stream)
        {
            var cm = new HttpRequestCommand(url);

            cm.SetBodyStream(stream);
            return(this.GetBodyTextAsync(cm));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public Task <HttpResponse> GetResponseAsync(String url, Byte[] data)
        {
            var cm = new HttpRequestCommand(url);

            cm.SetBodyStream(data);
            return(this.GetResponseAsync(cm));
        }
Пример #6
0
        public static CookieContainer GetCookieContainer(String url, Encoding responseEncoding, String idKey, String id, String passwordKey, String password
                                                         , Dictionary <String, String> values)
        {
            CookieContainer cc = new CookieContainer();
            HttpClient      cl = new HttpClient();

            cl.ResponseEncoding = responseEncoding;
            cl.CookieContainer  = cc;

            var cm = new HttpRequestCommand(url);

            cm.ContentType = HttpClient.ApplicationFormUrlEncoded;
            cm.MethodName  = HttpMethodName.Post;
            var d = cm.Headers;

            d[idKey]       = id;
            d[passwordKey] = password;
            foreach (var key in values.Keys)
            {
                d[key] = values[key];
            }
            var res = cl.GetResponse(cm);

            return(cc);
        }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        public RssFeed GetRssFeed(Uri uri)
        {
            var cm   = new HttpRequestCommand(uri.ToString());
            var body = this.GetBodyText(cm);

            return(RssFeed.Parse(body));
        }
Пример #8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        public RssFeed GetRssFeed(Uri uri)
        {
            var cm = new HttpRequestCommand(uri.ToString());
            var body = this.GetBodyText(cm);

            return RssFeed.Parse(body);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public Task <HttpWebResponse> GetHttpWebResponseAsync(String url, HttpBodyFormUrlEncodedData data)
        {
            var cm = new HttpRequestCommand(url);

            cm.SetBodyStream(data);
            return(this.GetHttpWebResponseAsync(cm));
        }
Пример #10
0
        public void GetHttpWebResponse(HttpRequestCommand command, Action <HttpWebResponse> callback, Action <AsyncHttpCallErrorEventArgs> errorCallback)
        {
            var req             = this.CreateRequest(command);
            AsyncHttpContext cx = this.CreateAsyncHttpContext(command, callback);

            cx.Uploading += (o, e) => this.OnUploading(e);
            cx.Error     += (o, e) => errorCallback(e);
            cx.BeginRequest(req);
        }
Пример #11
0
        public void GetResponse(HttpRequestCommand command, Action <HttpResponse> callback)
        {
            var req             = this.CreateRequest(command);
            AsyncHttpContext cx = this.CreateAsyncHttpContext(command, res => this.GetResponseCallback(res, callback));

            cx.Uploading += (o, e) => this.OnUploading(e);
            cx.Error     += (o, e) => this.GetResponseErrorCallback(e, callback);
            cx.BeginRequest(req);
        }
Пример #12
0
        protected Task <TResult> AsyncCall <TResult>(HttpRequestCommand command, Func <HttpResponse, TResult> func)
        {
            var source = new TaskCompletionSource <TResult>();

            this.GetHttpWebResponse(command
                                    , res => source.SetResult(func(new HttpResponse(res, this.ResponseEncoding)))
                                    , e => source.SetException(e.Exception));
            return(source.Task);
        }
Пример #13
0
        protected AsyncHttpContext CreateAsyncHttpContext(HttpRequestCommand command, Action <HttpWebResponse> callback)
        {
            AsyncHttpContext cx = new AsyncHttpContext(command, this.AsyncHttpContextCallback(callback));

            if (this.RequestBufferSize.HasValue == true)
            {
                cx.RequestBufferSize = this.RequestBufferSize;
            }
            return(cx);
        }
Пример #14
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public OAuth1AuthorizeInfo GetAuthorizeInfo()
        {
            String             url      = this.RequestTokenUrl;
            var                cm       = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret, "", "", HttpMethodName.Post);
            SignatureInfo      si       = OAuth1Client.GenerateSignature(new Uri(url), cm, OAuthSignatureTypes.HMACSHA1);
            HttpRequestCommand command  = this.CreateHttpRequestCommand(HttpMethodName.Post, url, "", "");
            String             bodyText = this.GetBodyText(command);

            //正規表現でoauth_token,oauth_token_secret取得
            return(OAuth1AuthorizeInfo.Create(this.AuthorizeUrl, bodyText));
        }
Пример #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="requestToken"></param>
        /// <param name="requestTokenSecret"></param>
        /// <returns></returns>
        public OAuth1AccessToken GetAccessToken(String requestToken, String requestTokenSecret)
        {
            String url = this.AccessTokenUrl;
            GetRequestTokenCommand cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret
                                                                   , requestToken, requestTokenSecret, HttpMethodName.Post);
            SignatureInfo      si      = OAuth1Client.GenerateSignature(new Uri(url), cm, OAuthSignatureTypes.HMACSHA1);
            HttpRequestCommand command =
                new HttpRequestCommand(String.Format("{0}?{1}&oauth_signature={2}", url, si.NormalizedRequestParameters, si.Signature), HttpMethodName.Post);
            var res = this.GetResponse(command);

            return(OAuth1AccessToken.Create(res.BodyText));
        }
Пример #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="authorizeInfo"></param>
        /// <param name="oauthVerifier"></param>
        /// <returns></returns>
        public OAuth1AccessToken GetAccessToken(OAuth1AuthorizeInfo authorizeInfo, String oauthVerifier)
        {
            var ai = authorizeInfo;
            var cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret
                                                , ai.RequestToken, ai.RequestTokenSecret, HttpMethodName.Post);
            var si = OAuth1Client.GenerateSignature(new Uri(this.AccessTokenUrl), cm, OAuthSignatureTypes.HMACSHA1);
            HttpRequestCommand command = new HttpRequestCommand(String.Format("{0}?{1}&oauth_verifier={2}&oauth_signature={3}"
                                                                              , this.AccessTokenUrl, si.NormalizedRequestParameters, oauthVerifier, si.Signature), HttpMethodName.Post);
            var res = this.GetResponse(command);

            return(OAuth1AccessToken.Create(res.BodyText));
        }
Пример #17
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public OAuth1AuthorizeInfo GetAuthorizeInfo()
        {
            String             url     = this.RequestTokenUrl;
            var                cm      = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret, "", "", HttpMethodName.Post);
            SignatureInfo      si      = OAuth1Client.GenerateSignature(new Uri(url), cm, OAuthSignatureTypes.HMACSHA1);
            HttpRequestCommand command =
                new HttpRequestCommand(String.Format("{0}?{1}&oauth_signature={2}", url, si.NormalizedRequestParameters, si.Signature), HttpMethodName.Post);
            String bodyText = this.GetBodyText(command);

            //正規表現でoauth_token,oauth_token_secret取得
            return(OAuth1AuthorizeInfo.Create(this.AuthorizeUrl, bodyText));
        }
Пример #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="authorizeInfo"></param>
        /// <param name="oauthVerifier"></param>
        /// <returns></returns>
        public AccessTokenInfo GetAccessToken(AuthorizeInfo authorizeInfo, String oauthVerifier)
        {
            var ai = authorizeInfo;
            var cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret
                                                , ai.RequestToken, ai.RequestTokenSecret, HttpMethodName.Post);
            var si = OAuthClient.GenerateSignature(new Uri(this.AccessTokenUrl), cm, OAuthSignatureTypes.HMACSHA1);
            HttpRequestCommand command = new HttpRequestCommand(String.Format("{0}?{1}&oauth_verifier={2}&oauth_signature={3}"
                                                                              , this.AccessTokenUrl, si.NormalizedRequestParameters, oauthVerifier, si.Signature), HttpMethodName.Post);
            HttpClient cl = new HttpClient();
            String     s  = cl.GetBodyText(command);

            return(AccessTokenInfo.Create(s, "oauth_token", "oauth_token_secret"));
        }
Пример #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="requestToken"></param>
        /// <param name="requestTokenSecret"></param>
        /// <returns></returns>
        public AccessTokenInfo GetAccessToken(String requestToken, String requestTokenSecret)
        {
            String url = this.AccessTokenUrl;
            GetRequestTokenCommand cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret
                                                                   , requestToken, requestTokenSecret, HttpMethodName.Post);
            SignatureInfo      si      = OAuthClient.GenerateSignature(new Uri(url), cm, OAuthSignatureTypes.HMACSHA1);
            HttpRequestCommand command =
                new HttpRequestCommand(String.Format("{0}?{1}&oauth_signature={2}", url, si.NormalizedRequestParameters, si.Signature), HttpMethodName.Post);
            HttpClient cl     = new HttpClient();
            String     result = cl.GetBodyText(command);

            return(AccessTokenInfo.Create(result, "oauth_token", "oauth_token_secret"));
        }
Пример #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="methodName"></param>
        /// <param name="url"></param>
        /// <param name="token"></param>
        /// <param name="tokenSecret"></param>
        /// <param name="queryString"></param>
        /// <returns></returns>
        public HttpRequestCommand CreateHttpRequestCommand(HttpMethodName methodName, String url, String token, String tokenSecret, IDictionary <String, String> queryString)
        {
            HttpRequestCommand cm = null;

            switch (this.Mode)
            {
            case OAuthMode.QueryString: cm = this.CreateHttpClientQueryStringMode(methodName, url, token, tokenSecret, queryString); break;

            case OAuthMode.Header: cm = this.CreateHttpClientRequestHeaderMode(methodName, url, token, tokenSecret, queryString); break;

            default: throw new InvalidOperationException();
            }
            return(cm);
        }
Пример #21
0
        public void GetHttpWebResponse(String url, Stream stream, Action <HttpWebResponse> callback)
        {
            var cm              = new HttpRequestCommand(url, stream);
            var req             = this.CreateRequest(cm);
            AsyncHttpContext cx = new AsyncHttpContext(cm, this.AsyncHttpContextCallback(callback));

            if (this.RequestBufferSize.HasValue == true)
            {
                cx.RequestBufferSize = this.RequestBufferSize.Value;
            }
            cx.Uploading += (o, e) => this.OnUploading(e);
            cx.Error     += (o, e) => this.OnError(e);
            cx.BeginRequest(req);
        }
Пример #22
0
        private HttpRequestCommand CreateHttpClientRequestHeaderMode(HttpMethodName methodName, String url, String token, String tokenSecret, IDictionary <String, String> queryString)
        {
            var cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret, token, tokenSecret, methodName);
            Dictionary <String, String> pp = OAuth1Client.GenerateParameters(cm);
            var           u  = new Uri(HttpClient.CreateQueryString(url, queryString, OAuth1Client.UrlEncode));
            SignatureInfo si = GenerateSignature(u, cm);

            pp.Add("oauth_signature", OAuth1Client.UrlEncode(si.Signature));
            HttpRequestCommand cl = new HttpRequestCommand(HttpClient.CreateQueryString(url, queryString, HttpClient.UrlEncode));

            cl.MethodName = methodName;
            cl.Headers[HttpRequestHeader.Authorization] = this.CreateOAuthHeader(pp);
            return(cl);
        }
Пример #23
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public AuthorizeInfo GetAuthorizeInfo()
        {
            String             url     = this.RequestTokenUrl;
            var                cm      = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret, "", "", HttpMethodName.Post);
            SignatureInfo      si      = OAuthClient.GenerateSignature(new Uri(url), cm, OAuthSignatureTypes.HMACSHA1);
            HttpClient         cl      = new HttpClient();
            HttpRequestCommand command =
                new HttpRequestCommand(String.Format("{0}?{1}&oauth_signature={2}", url, si.NormalizedRequestParameters, si.Signature), HttpMethodName.Post);
            String result = cl.GetBodyText(command);
            //正規表現でoauth_token,oauth_token_secret取得
            AuthorizeInfo ai = new AuthorizeInfo();

            ai.AuthorizeUrl       = String.Format("{0}?{1}", this.AuthorizeUrl, result);
            ai.RequestToken       = this.GetMatchValue(RegexList.OAuthToken, result);
            ai.RequestTokenSecret = this.GetMatchValue(RegexList.OAuthTokenSecret, result);
            return(ai);
        }
Пример #24
0
        private HttpRequestCommand CreateHttpClientQueryStringMode(HttpMethodName methodName, String url, String token, String tokenSecret, IDictionary <String, String> queryString)
        {
            var cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret, token, tokenSecret, methodName);
            Dictionary <String, String> pp = OAuth1Client.GenerateParameters(cm);

            foreach (var p in queryString)
            {
                pp.Add(p.Key, p.Value);
            }
            var           u  = new Uri(HttpClient.CreateQueryString(url, pp, OAuth1Client.UrlEncode));
            SignatureInfo si = GenerateSignature(u, cm);

            pp.Add("oauth_signature", OAuth1Client.UrlEncode(si.Signature));
            HttpRequestCommand cl = new HttpRequestCommand(HttpClient.CreateQueryString(url, pp, HttpClient.UrlEncode));

            cl.MethodName = methodName;
            return(cl);
        }
Пример #25
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="url"></param>
        /// <param name="responseEncoding"></param>
        /// <param name="idKey"></param>
        /// <param name="id"></param>
        /// <param name="passwordKey"></param>
        /// <param name="password"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public static CookieContainer GetCookieContainer(String url, Encoding responseEncoding, String idKey, String id, String passwordKey, String password
            , Dictionary<String, String> values)
        {
            CookieContainer cc = new CookieContainer();
            HttpClient cl = new HttpClient();
            cl.ResponseEncoding = responseEncoding;
            cl.CookieContainer = cc;

            var cm = new HttpRequestCommand(url);
            cm.ContentType = HttpClient.ApplicationFormUrlEncoded;
            cm.MethodName = HttpMethodName.Post;
            var d = cm.Headers;
            d[idKey] = id;
            d[passwordKey] = password;
            foreach (var key in values.Keys)
            {
                d[key] = values[key];
            }
            var res = cl.GetResponse(cm);

            return cc;
        }
Пример #26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public HttpWebRequest CreateRequest(HttpRequestCommand command)
        {
            HttpWebRequest req = HttpWebRequest.Create(command.Url) as HttpWebRequest;

            req.Method      = command.MethodName.ToString().ToUpper();
            req.ContentType = command.ContentType;
            if (this.CookieContainer != null)
            {
                req.CookieContainer = this.CookieContainer;
            }
            if (this.Credentials != null)
            {
                req.Credentials = this.Credentials;
            }
#if !SILVERLIGHT
            req.ClientCertificates.AddRange(this.ClientCertificates);
#endif
            foreach (String key in command.Headers.AllKeys)
            {
                req.Headers[key] = command.Headers[key];
            }
            return(req);
        }
Пример #27
0
        protected Task <TResult> AsyncCall <TResult>(HttpRequestCommand command, Func <HttpWebResponse, TResult> func)
        {
            var source = new TaskCompletionSource <TResult>();

            this.GetHttpWebResponse(command
                                    , res => source.SetResult(func(res))
                                    , e =>
            {
                var ex = e.Exception as WebException;
                if (ex == null)
                {
                    source.SetException(e.Exception);
                    return;
                }
                var res = ex.Response as HttpWebResponse;
                if (res == null)
                {
                    source.SetException(e.Exception);
                    return;
                }
                source.SetResult(func(res));
            });
            return(source.Task);
        }
Пример #28
0
        public HttpResponse GetResponse(HttpRequestCommand command)
        {
            HttpWebResponse res = null;
            HttpResponse    hr  = null;

            try
            {
                res = this.GetHttpWebResponse(command);
                hr  = new HttpResponse(res, this);
            }
            catch (WebException ex)
            {
                res = ex.Response as HttpWebResponse;
                if (res != null)
                {
                    hr = new HttpResponse(res, this);
                }
                else
                {
                    throw;
                }
            }
            return(hr);
        }
Пример #29
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public void GetRssFeed(Uri uri, Action<RssFeed> callback)
 {
     var cm = new HttpRequestCommand(uri.ToString());
     this.GetBodyText(cm, body => callback(RssFeed.Parse(body)));
 }
Пример #30
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="command"></param>
 /// <returns></returns>
 public HttpResponse GetResponse(HttpRequestCommand command)
 {
     HttpWebResponse res = null;
     HttpResponse hr = null;
     try
     {
         res = this.GetHttpWebResponse(command);
         hr = new HttpResponse(res, this);
     }
     catch (WebException ex)
     {
         res = ex.Response as HttpWebResponse;
         if (res != null)
         {
             hr = new HttpResponse(res, this);
         }
         else
         {
             throw;
         }
     }
     return hr;
 }
Пример #31
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public HttpWebResponse GetHttpWebResponse(HttpRequestCommand command)
        {
            HttpWebRequest req = this.CreateRequest(command);
            StreamWriteContext scx = null;

            if (command.BodyStream != null && command.IsSendBodyStream == true)
            {
                //Request body
                //req.ContentLength = command.BodyStream.Length;
                if (command.BodyStream.Length > 0)
                {
                    using (var stm = req.GetRequestStream())
                    {
                        if (this.RequestBufferSize.HasValue == true)
                        {
                            scx = new StreamWriteContext(stm, this.RequestBufferSize.Value);
                        }
                        else
                        {
                            scx = new StreamWriteContext(stm);
                        }
                        scx.Uploading += (o, e) => this.OnUploading(e);
                        scx.Write(command.BodyStream);
                        stm.Dispose();
                    }
                }
            }
            return req.GetResponse() as HttpWebResponse;
        }
Пример #32
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="command"></param>
 /// <returns></returns>
 public String GetBodyText(HttpRequestCommand command)
 {
     var res = this.GetResponse(command);
     return res.BodyText;
 }
Пример #33
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public void GetRssFeed(Uri uri, Action <RssFeed> callback)
        {
            var cm = new HttpRequestCommand(uri.ToString());

            this.GetBodyText(cm, body => callback(RssFeed.Parse(body)));
        }
Пример #34
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="command"></param>
 /// <returns></returns>
 public Task <HttpWebResponse> GetHttpWebResponseAsync(HttpRequestCommand command)
 {
     return(AsyncCall <HttpRequestCommand, HttpWebResponse>(this.GetHttpWebResponse, command));
 }
Пример #35
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="command"></param>
 /// <param name="requestBufferSize"></param>
 /// <param name="callback"></param>
 public AsyncHttpContext(HttpRequestCommand command, Int32 requestBufferSize, Action<HttpWebResponse> callback)
 {
     _Command = command;
     this.RequestBufferSize = requestBufferSize;
     _Callback = callback;
 }
Пример #36
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="command"></param>
 /// <returns></returns>
 public Task <String> GetBodyTextAsync(HttpRequestCommand command)
 {
     return(AsyncCall <HttpRequestCommand, String>(this.GetBodyText, command));
 }
Пример #37
0
 private HttpRequestCommand CreateHttpClientQueryStringMode(HttpMethodName methodName, String url, String token, String tokenSecret, IDictionary<String, String> queryString)
 {
     var cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret, token, tokenSecret, methodName);
     Dictionary<String, String> pp = OAuth1Client.GenerateParameters(cm);
     foreach (var p in queryString)
     {
         pp.Add(p.Key, p.Value);
     }
     var u = new Uri(HttpClient.CreateQueryString(url, pp, OAuth1Client.UrlEncode));
     SignatureInfo si = GenerateSignature(u, cm);
     pp.Add("oauth_signature", OAuth1Client.UrlEncode(si.Signature));
     HttpRequestCommand cl = new HttpRequestCommand(HttpClient.CreateQueryString(url, pp, HttpClient.UrlEncode));
     cl.MethodName = methodName;
     return cl;
 }
Пример #38
0
 private HttpRequestCommand CreateHttpClientRequestHeaderMode(HttpMethodName methodName, String url, String token, String tokenSecret, IDictionary<String, String> queryString)
 {
     var cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret, token, tokenSecret, methodName);
     Dictionary<String, String> pp = OAuth1Client.GenerateParameters(cm);
     var u = new Uri(HttpClient.CreateQueryString(url, queryString, OAuth1Client.UrlEncode));
     SignatureInfo si = GenerateSignature(u, cm);
     pp.Add("oauth_signature", OAuth1Client.UrlEncode(si.Signature));
     HttpRequestCommand cl = new HttpRequestCommand(HttpClient.CreateQueryString(url, queryString, HttpClient.UrlEncode));
     cl.MethodName = methodName;
     cl.Headers[HttpRequestHeader.Authorization] = this.CreateOAuthHeader(pp);
     return cl;
 }
        private String CallApi(VimeoApiEndpointInfo apiInfo, Dictionary<String, String> parameters)
        {
            var cl = new HttpClient();
            var methodName = apiInfo.HttpMethodName.ToEnum<HttpMethodName>().Value;
            var qs = new QueryStringConverter();
            var url = String.Format("https://api.vimeo.com/{0}?{1}", apiInfo.ApiPath, qs.Write(parameters));
            foreach (var key in _IDParameterValues.Keys)
            {
                url = url.Replace("{" + key + "}", _IDParameterValues[key]);
            }

            var cm = new HttpRequestCommand(url);
            cm.MethodName = methodName;
            if (cm.MethodName != HttpMethodName.Get)
            {
                cm.SetBodyStream(new HttpBodyFormUrlEncodedData(parameters));
            }
            var json = cl.GetBodyText(cm);
            return json;
        }
Пример #40
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="command"></param>
 /// <param name="callback"></param>
 public AsyncHttpContext(HttpRequestCommand command, Action<HttpWebResponse> callback)
 {
     _Command = command;
     _Callback = callback;
 }
Пример #41
0
 public void GetBodyText(HttpRequestCommand command, Action <String> callback)
 {
     this.GetHttpWebResponse(command, res => this.GetBodyTextCallback(res, callback));
 }