/// <summary> /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an /// <see cref="OAuthWebQuery" /> for the purpose of requesting an /// unauthorized request token. /// </summary> /// <param name="method">The HTTP method for the intended request</param> /// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param> /// <seealso cref="http://oauth.net/core/1.0#anchor9"/> /// <returns></returns> public OAuthWebQueryInfo BuildRequestTokenInfo(WebMethod method, WebParameterCollection parameters) { ValidateTokenRequestState(); if (parameters == null) { parameters = new WebParameterCollection(); } var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); AddAuthParameters(parameters, timestamp, nonce); var signatureBase = OAuthTools.ConcatenateRequestElements(method, RequestTokenUrl, parameters); var signature = OAuthTools.GetSignature(SignatureMethod, signatureBase, ConsumerSecret); var info = new OAuthWebQueryInfo { WebMethod = method, ParameterHandling = ParameterHandling, ConsumerKey = ConsumerKey, SignatureMethod = SignatureMethod.ToRequestValue(), Signature = signature, Timestamp = timestamp, Nonce = nonce, Version = OAUTH_VERSION, Callback = OAuthTools.UrlEncode(CallbackUrl ?? ""), UserAgent = "TweetSharp", TokenSecret = TokenSecret, ConsumerSecret = ConsumerSecret }; return info; }
public WebQuery GetQueryFor(string url, RestBase request, IWebQueryInfo info, WebMethod method) { return GetQueryForImpl(info); }
/// <summary> /// Declares a method presentend in the automatically-generated JavaScript API for a file/object of this type. /// </summary> /// <param name="name">The method name in the JavaScript API. JavaScript does not support overloading, so use different names for variations on arguments or web methods.</param> /// <param name="webMethod">The web request method, either GET, POST, or PUT</param> /// <param name="documentation">The method's documention that's put into metadata</param> /// <param name="returnType">The kind of value returned by the method, either a value or a JSON-encoded object</param> public JavaScriptMethodAttribute(string name, WebMethod webMethod, string documentation, JavaScriptType returnType) { _Name = name; _WebMethod = webMethod; _Documentation = documentation; _ReturnType = ReturnType; }
public ShellWebConnection( IWebConnection webConnection, WebMethod method, string url, byte[] content, string contentType, CookiesFromBrowser cookiesFromBrowser, CallingFrom callingFrom) : base(webConnection.WebServer, callingFrom, webConnection.Generation + 1) { _Content = new WebConnectionContent.InMemory(content); _ContentType = contentType; _Session = webConnection.Session; _Method = method; _CookiesFromBrowser = cookiesFromBrowser; _CookiesToSet = webConnection.CookiesToSet; _HttpVersion = webConnection.HttpVersion; _RequestedHost = webConnection.RequestedHost; _Headers = new Dictionary<string, string>(webConnection.Headers); _MimeReader = webConnection.MimeReader; BaseWebConnection = webConnection; DetermineRequestedFileAndGetParameters(url); TryDecodePostParameters(); }
public static HttpWebRequest CreateWebRequest(WebMethod method, WebProxy proxy, string requestUrl, bool preAuth) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl); request.Method = method.ToString(); request.PreAuthenticate = preAuth; request.Proxy = proxy; return request; }
public static HttpWebRequest CreateWebRequest(string fullUrl, WebMethod method, string nonce, string timeStamp, string sig, string contentType, OAuthToken consumerToken, OAuthToken oauthToken, WebProxy proxy) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fullUrl); request.Method = method.ToString(); request.Proxy = proxy; string authHeader = CreateAuthHeader(method, nonce, timeStamp, sig, consumerToken, oauthToken); //request.ContentType = "multipart/form-data; boundary=" + boundary; request.ContentType = contentType; request.Headers.Add("Authorization", authHeader); return request; }
public BlockingShellWebConnection( IWebConnection webConnection, WebMethod method, string url, byte[] content, string contentType, CookiesFromBrowser cookiesFromBrowser, CallingFrom callingFrom) : base(webConnection, method, url, content, contentType, cookiesFromBrowser, callingFrom) { }
public BlockingShellWebConnection( IWebServer webServer, ISession session, string url, byte[] content, string contentType, CookiesFromBrowser cookiesFromBrowser, CallingFrom callingFrom, WebMethod method) : base(webServer, session, url, content, contentType, cookiesFromBrowser, callingFrom, method) { }
protected WebCallableMethod(MethodInfo methodInfo, WebCallableAttribute webCallableAttribute, WebMethod? webMethod) { _MethodInfo = methodInfo; _WebCallableAttribute = webCallableAttribute; _WebMethod = webMethod; _Parameters = _MethodInfo.GetParameters(); for (uint parameterCtr = 0; parameterCtr < _Parameters.Length; parameterCtr++) ParameterIndexes[_Parameters[parameterCtr].Name] = parameterCtr; List<string> namedPermissions = new List<string>(); foreach (NamedPermissionAttribute npa in methodInfo.GetCustomAttributes(typeof(NamedPermissionAttribute), true)) namedPermissions.Add(npa.NamedPermission); _NamedPermissions = namedPermissions.ToArray(); }
public static string CallApiMethod( WebMethod method, Uri uri, Dictionary<string, string> headers, bool needsKey, Data data) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "GET"; request.KeepAlive = true; request.ProtocolVersion = HttpVersion.Version11; //request.Headers.Add("Authorization", (string)pars["access_token"]); request.Headers.Add("Authorization", "Bearer " + (string)pars["access_token"]); if (needsKey) { request.Headers.Add("X-GData-Key", "key=" + Globals.DevKey); } if (data != null && data.usesData) { Byte[] brutes = Encoding.UTF8.GetBytes(data.data); request.ContentLength = brutes.Length; Stream requestStream = (Stream)request.GetRequestStream(); requestStream.Write(brutes, 0, brutes.Length); requestStream.Close(); } try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); String text = (new StreamReader(response.GetResponseStream())).ReadToEnd(); return text; } catch (Exception e) { throw new Exception("Invalid request.", e); } }
protected void DoRequest(string sEndpoint, WebMethod wmTransferType, Dictionary<string, string> dssParams, APIReturn aprReturn) { RestRequest rrRequest = new RestRequest(); rrRequest.Path = sEndpoint; m_oaCredentials.Type = OAuthType.ProtectedResource; m_oaCredentials.Verifier = null; foreach (KeyValuePair<string, string> kvpCur in dssParams) rrRequest.AddParameter(kvpCur.Key, kvpCur.Value); RestClient rcClient = new RestClient { Authority = C_BASE_URL, VersionPath = "1", Credentials = m_oaCredentials, Method = wmTransferType }; rcClient.BeginRequest(rrRequest, DoRequestCallback, aprReturn); }
public static string GetSignature(WebMethod method, OAuthToken consumerToken, OAuthToken oauthToken, string url, out string timestamp, out string nonce) { OAuthBase oAuth = new OAuthBase(); nonce = oAuth.GenerateNonce(); timestamp = oAuth.GenerateTimeStamp(); string nurl, nrp; string tokenKey = oauthToken == null ? String.Empty : oauthToken.TokenKey; string tokenSecret = oauthToken == null ? String.Empty : oauthToken.TokenSecret; Uri uri = new Uri(url); string sig = oAuth.GenerateSignature( uri, consumerToken.TokenKey, consumerToken.TokenSecret, tokenKey, tokenSecret, method.ToString(), timestamp, nonce, OAuthBase.SignatureTypes.HMACSHA1, out nurl, out nrp); return System.Web.HttpUtility.UrlEncode(sig); }
public WebQuery GetQueryFor(string url, RestBase request, IWebQueryInfo info, WebMethod method, bool enableTrace) { return GetQueryForImpl(info, enableTrace); }
/// <summary> /// Constructor for when a web request is generated publicly instead of externally /// </summary> /// <param name="webServer"></param> /// <param name="session"></param> /// <param name="url"></param> /// <param name="content"></param> /// <param name="contentType"></param> /// <param name="cookiesFromBrowser"></param> /// <param name="callingFrom"></param> /// <param name="method"></param> public ShellWebConnection( IWebServer webServer, ISession session, string url, byte[] content, string contentType, CookiesFromBrowser cookiesFromBrowser, CallingFrom callingFrom, WebMethod method) : base(webServer, callingFrom, 0) { _Content = new WebConnectionContent.InMemory(content); _ContentType = contentType; _Session = session; _Method = method; _CookiesFromBrowser = cookiesFromBrowser; _CookiesToSet = new List<CookieToSet>(); _HttpVersion = 1; _RequestedHost = null; _Headers = new Dictionary<string, string>(); DetermineRequestedFileAndGetParameters(url); TryDecodePostParameters(); if (null == BaseWebConnection) BaseWebConnection = this; }
public static string GetSignature(WebMethod method, string url, out string timestamp, out string nonce) { OAuthBase oAuth = new OAuthBase(); nonce = oAuth.GenerateNonce(); timestamp = oAuth.GenerateTimeStamp(); string nurl, nrp; Uri uri = new Uri(url); string sig = oAuth.GenerateSignature( uri, Yammer.Session.Auth.Key.ConsumerKey, Yammer.Session.Auth.Key.ConsumerSecret, Yammer.Session.Auth.Key.TokenKey, Yammer.Session.Auth.Key.TokenSecret, method.ToString(), timestamp, nonce, OAuthBase.SignatureTypes.PLAINTEXT, out nurl, out nrp); return System.Web.HttpUtility.UrlEncode(sig); }
private static HttpWebRequest CreateWebRequest(string fullUrl, WebMethod method, string[] oauthParams) { string nonce, timeStamp, sig; nonce = oauthParams[0]; timeStamp = oauthParams[1]; sig = oauthParams[2]; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fullUrl); request.ServicePoint.Expect100Continue = false; request.KeepAlive = false; request.ProtocolVersion = HttpVersion.Version10; request.Method = method.ToString(); request.Proxy = Yammer.Session.WebProxy; string authHeader = CreateAuthHeader(method, nonce, timeStamp, sig); request.ContentType = "text/plain"; request.Headers.Add("Authorization", authHeader); return request; }
private static string CreateAuthHeader(WebMethod method, string nonce, string timeStamp, string sig) { StringBuilder sb = new StringBuilder(); sb.Append("OAuth "); if (method == WebMethod.POST) sb.Append("realm=\"" + "\","); else sb.Append("realm=\"\","); string authHeader = "oauth_consumer_key=\"" + Yammer.Session.Auth.Key.ConsumerKey + "\"," + "oauth_token=\"" + Yammer.Session.Auth.Key.TokenKey + "\"," + "oauth_nonce=\"" + nonce + "\"," + "oauth_timestamp=\"" + timeStamp + "\"," + "oauth_signature_method=\"" + "PLAINTEXT" + "\"," + "oauth_version=\"" + "1.0" + "\"," + "oauth_signature=\"" + sig + "\""; sb.Append(authHeader); return sb.ToString(); //Authorization: OAuth realm="", oauth_consumer_key="AMbmZSOP3wHm1cjfvSsRg", oauth_signature_method="HMAC-SHA1", oauth_signature="yLDH5eLS4uUVa3vVbNxvDX9B8aFgnwRSFla3jph9y90%26", oauth_timestamp="1229537444", oauth_nonce="1229537444", oauth_version="1.0" }
public string GetResponse(WebMethod method, string url, string postData) { IResponseReader responseReader = GetResponseReader(method, url, postData); return responseReader.ReadToEnd(); }
public virtual OAuthWebQueryInfo BuildProtectedResourceInfo(WebMethod method, WebParameterCollection parameters, string url) { ValidateProtectedResourceState(); if (parameters == null) { parameters = new WebParameterCollection(); } // Include url parameters in query pool var uri = new Uri(url); #if !SILVERLIGHT var urlParameters = System.Compat.Web.HttpUtility.ParseQueryString(uri.Query); #else var urlParameters = uri.Query.ParseQueryString(); #endif #if !SILVERLIGHT foreach (var parameter in urlParameters.AllKeys) #else foreach (var parameter in urlParameters.Keys) #endif { switch (method) { case WebMethod.Post: parameters.Add(new HttpPostParameter(parameter, urlParameters[parameter])); break; default: parameters.Add(parameter, urlParameters[parameter]); break; } } var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); // [DC] Make a copy of the parameters so that the signature double-encode isn't used var copy = new WebParameterCollection(); foreach(var parameter in parameters) { copy.Add(new WebPair(parameter.Name, parameter.Value)); } AddAuthParameters(copy, timestamp, nonce); // [DC] Escape parameters at this point; do not escape again if recalculating var signatureBase = OAuthTools.ConcatenateRequestElements(method, url, copy); var signature = OAuthTools.GetSignature( SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret ); var info = new OAuthWebQueryInfo { WebMethod = method, ParameterHandling = ParameterHandling, ConsumerKey = ConsumerKey, Token = Token, SignatureMethod = SignatureMethod.ToRequestValue(), SignatureTreatment = SignatureTreatment, Signature = signature, Timestamp = timestamp, Nonce = nonce, Version = Version ?? "1.0", Callback = CallbackUrl, UserAgent = "Hammock", ConsumerSecret = ConsumerSecret, TokenSecret = TokenSecret }; return info; }
private IAsyncResult WithHammock <T>(WebMethod method, Action <T, TwitterResponse> action, string path, params object[] segments) where T : class { return(WithHammock(method, action, ResolveUrlSegments(path, segments.ToList()))); }
private T WithHammock <T>(RestClient client, WebMethod method, string path, params object[] segments) { var url = ResolveUrlSegments(path, segments.ToList()); return(WithHammock <T>(client, method, url)); }
private void WithHammockNoResponse(RestClient client, WebMethod method, string path, params object[] segments) { BeginWithHammockNoResponse(client, method, path, segments); }
/// <summary> /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an /// <see cref="OAuthWebQuery" /> for the purpose of requesting an /// unauthorized request token. /// </summary> /// <param name="method">The HTTP method for the intended request</param> /// <seealso cref="http://oauth.net/core/1.0#anchor9"/> /// <returns></returns> public OAuthWebQueryInfo BuildRequestTokenInfo(WebMethod method) { return(BuildRequestTokenInfo(method, null)); }
public virtual OAuthWebQueryInfo BuildProtectedResourceInfo(WebMethod method, WebParameterCollection parameters, string url) { ValidateProtectedResourceState(); if (parameters == null) { parameters = new WebParameterCollection(); } // Include url parameters in query pool var uri = new Uri(url); #if !SILVERLIGHT var urlParameters = System.Compat.Web.HttpUtility.ParseQueryString(uri.Query); #else var urlParameters = uri.Query.ParseQueryString(); #endif #if !SILVERLIGHT foreach (var parameter in urlParameters.AllKeys) #else foreach (var parameter in urlParameters.Keys) #endif { switch (method) { case WebMethod.Post: parameters.Add(new HttpPostParameter(parameter, urlParameters[parameter])); break; default: parameters.Add(parameter, urlParameters[parameter]); break; } } var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); // [DC] Make a copy of the parameters so that the signature double-encode isn't used var copy = new WebParameterCollection(); foreach (var parameter in parameters) { copy.Add(new WebPair(parameter.Name, parameter.Value)); } AddAuthParameters(copy, timestamp, nonce); // [DC] Escape parameters at this point; do not escape again if recalculating var signatureBase = OAuthTools.ConcatenateRequestElements(method, url, copy); var signature = OAuthTools.GetSignature( SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret ); var info = new OAuthWebQueryInfo { WebMethod = method, ParameterHandling = ParameterHandling, ConsumerKey = ConsumerKey, Token = Token, SignatureMethod = SignatureMethod.ToRequestValue(), SignatureTreatment = SignatureTreatment, Signature = signature, Timestamp = timestamp, Nonce = nonce, Version = Version ?? "1.0", Callback = CallbackUrl, UserAgent = "Hammock", ConsumerSecret = ConsumerSecret, TokenSecret = TokenSecret }; return(info); }
/// <summary> /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an /// <see cref="OAuthWebQuery" /> for the purpose of exchanging a request token /// for an access token authorized by the user at the Service Provider site. /// </summary> /// <param name="method">The HTTP method for the intended request</param> /// <seealso cref="http://oauth.net/core/1.0#anchor9"/> public virtual OAuthWebQueryInfo BuildAccessTokenInfo(WebMethod method) { return(BuildAccessTokenInfo(method, null)); }
private Task <TwitterAsyncResult <T1> > WithHammockTask <T1>(RestClient client, WebMethod method, string path, MediaFile media, params object[] segments) where T1 : class { var tcs = new TaskCompletionSource <TwitterAsyncResult <T1> >(); try { WithHammock <T1>(client, method, (Action <T1, TwitterResponse>)((v, r) => { try { tcs.SetResult(new TwitterAsyncResult <T1>(v, r)); } catch (Exception ex) { tcs.SetException(ex); } }), media, ResolveUrlSegments(path, segments.ToList()) ); } catch (Exception ex) { tcs.SetException(ex); } return(tcs.Task); }
/// <summary> /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an /// <see cref="OAuthWebQuery" /> for the purpose of exchanging user credentials /// for an access token authorized by the user at the Service Provider site. /// </summary> /// <param name="method">The HTTP method for the intended request</param> /// <seealso cref="http://tools.ietf.org/html/draft-dehora-farrell-oauth-accesstoken-creds-00#section-4"/> /// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param> public virtual OAuthWebQueryInfo BuildClientAuthAccessTokenInfo(WebMethod method, WebParameterCollection parameters) { ValidateClientAuthAccessRequestState(); if (parameters == null) { parameters = new WebParameterCollection(); } var uri = new Uri(AccessTokenUrl); var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); AddXAuthParameters(parameters, timestamp, nonce); var signatureBase = OAuthTools.ConcatenateRequestElements(method, uri.ToString(), parameters); var signature = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret); var info = new OAuthWebQueryInfo { WebMethod = method, ParameterHandling = ParameterHandling, ClientMode = "client_auth", ClientUsername = ClientUsername, ClientPassword = ClientPassword, ConsumerKey = ConsumerKey, SignatureMethod = SignatureMethod.ToRequestValue(), SignatureTreatment = SignatureTreatment, Signature = signature, Timestamp = timestamp, Nonce = nonce, Version = Version, UserAgent = "Hammock", TokenSecret = TokenSecret, ConsumerSecret = ConsumerSecret }; return info; }
private IAsyncResult WithHammockNoResponse(RestClient client, WebMethod method, Action <TwitterResponse> action, string path, MediaFile media, params object[] segments) { return(WithHammockNoResponse(client, method, action, media, ResolveUrlSegments(path, segments.ToList()))); }
/// <summary> /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an /// <see cref="OAuthWebQuery" /> for the purpose of requesting an /// unauthorized request token. /// </summary> /// <param name="method">The HTTP method for the intended request</param> /// <seealso cref="http://oauth.net/core/1.0#anchor9"/> /// <returns></returns> public OAuthWebQueryInfo BuildRequestTokenInfo(WebMethod method) { return BuildRequestTokenInfo(method, null); }
public static string CallByte(string url, WebMethod method = WebMethod.Post, string contentType = null, string content = null, byte[] text = null, string headerAccept = null, IEnumerable<Tuple<string, string>> headers = null) { var httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.Method = method.GetLibelle(); httpWebRequest.ContentType = contentType; httpWebRequest.Accept = headerAccept; if (headers != null) foreach (var header in headers) httpWebRequest.Headers.Add(header.Item1, header.Item2); if (content.Length > 0) { byte[] byteArray = (Encoding.UTF8).GetBytes(content); httpWebRequest.ContentLength = byteArray.Length + text.Length; using (Stream dataStream = httpWebRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Write(text, 0, text.Length); dataStream.Close(); } } try { Stream httpResponse = httpWebRequest.GetResponse().GetResponseStream(); if (null == httpResponse) return null; using (var streamReader = new StreamReader(httpResponse)) { return streamReader.ReadToEnd(); } } catch (Exception ex) { Console.WriteLine(ex.Message); return null; } }
/// <summary> /// Submit a web request using oAuth. /// </summary> /// <param name="method">GET or POST</param> /// <param name="url">The full url, including the querystring.</param> /// <param name="postData">Data to post (querystring format)</param> /// <returns>The web server response.</returns> public IResponseReader GetResponseReader(WebMethod method, string url, string postData) { string outUrl = ""; string querystring = ""; string ret = ""; //Setup postData for signing. //Add the postData to the querystring. if (method == WebMethod.POST) { if (postData.Length > 0) { //Decode the parameters and re-encode using the oAuth UrlEncode method. NameValueCollection qs = HttpUtility.ParseQueryString(postData); postData = ""; foreach (string key in qs.AllKeys) { if (postData.Length > 0) { postData += "&"; } qs[key] = HttpUtility.UrlDecode(qs[key]); qs[key] = this.UrlEncode(qs[key]); postData += key + "=" + qs[key]; } if (url.IndexOf("?") > 0) { url += "&"; } else { url += "?"; } url += postData; } } Uri uri = new Uri(url); string nonce = this.GenerateNonce(); string timeStamp = this.GenerateTimeStamp(); //Generate Signature string sig = this.GenerateSignature(uri, this.ConsumerKey, this.ConsumerSecret, this.Token, this.TokenSecret, this.CallBackUrl, this.OAuthVerifier, method.ToString(), timeStamp, nonce, out outUrl, out querystring); querystring += "&oauth_signature=" + UrlEncode(sig); //Convert the querystring to postData if (method == WebMethod.POST) { postData = querystring; querystring = ""; } if (querystring.Length > 0) { outUrl += "?"; } return new ResponseReader(method, outUrl + querystring, postData); }
public WebQuery GetQueryFor(string url, RestBase request, IWebQueryInfo info, WebMethod method, bool enableTrace) { return(GetQueryForImpl(info, enableTrace)); }
private static HttpWebRequest CreateWebRequest(string fullUrl, WebMethod method, string nonce, string timeStamp, string sig) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fullUrl); request.Method = method.ToString(); request.Proxy = Yammer.Session.WebProxy; string authHeader = CreateAuthHeader(method, nonce, timeStamp, sig); request.ContentType = "application/x-www-form-urlencoded"; request.Headers.Add("Authorization", authHeader); return request; }
public virtual CreateHttpResponseInfo ProcessInternal(PortalKeeperContext <SimpleEngineEvent> actionContext, WebMethod verb) { actionContext.SetVar("HttpVerb", verb); this.SelectedAction.ProcessRules(actionContext, SimpleEngineEvent.Run, true, true); var response = actionContext.GetResponse(); if (response == null && this.SelectedAction.DefaultResponse.Enabled) { response = this.SelectedAction.DefaultResponse.Entity; } return(response); }
public static HttpWebRequest CreateWebRequest(string fullUrl, WebMethod method, string nonce, string timeStamp, string sig, string boundary) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fullUrl); request.Method = method.ToString(); request.Proxy = Yammer.Session.WebProxy; string authHeader = CreateAuthHeader(method, nonce, timeStamp, sig); request.ContentType = "multipart/form-data; boundary=" + boundary; request.Headers.Add("Authorization", authHeader); return request; }
public virtual HttpResponseMessage Process(PortalKeeperContext <SimpleEngineEvent> actionContext, WebMethod verb) { var response = ProcessInternal(actionContext, verb); return(response?.CreateResponse(actionContext)); }
public ShellWebConnection( string url, IWebConnection webConnection, RequestParameters postParameters, CookiesFromBrowser cookiesFromBrowser, CallingFrom callingFrom, WebMethod method) : base(webConnection.WebServer, callingFrom, webConnection.Generation + 1) { _PostParameters = postParameters; _Content = webConnection.Content; _ContentType = webConnection.ContentType; _Session = webConnection.Session; _Method = method; _CookiesFromBrowser = cookiesFromBrowser; _CookiesToSet = webConnection.CookiesToSet; _HttpVersion = webConnection.HttpVersion; _RequestedHost = webConnection.RequestedHost; _Headers = new Dictionary<string, string>(webConnection.Headers); _MimeReader = webConnection.MimeReader; BaseWebConnection = webConnection; DetermineRequestedFileAndGetParameters(url); }
public WebQuery GetQueryFor(string url, WebParameterCollection parameters, IWebQueryInfo info, WebMethod method) { return GetQueryForImpl(info); }
public void RenderFromText() { Load(false); try { var filepath = Path.Combine(_loadPath, "Setup"); var filetype = @"Request\"; var reqDirectories = Directory.GetDirectories(Path.Combine(filepath, filetype)); foreach (var file in reqDirectories) { var request = new ServiceObject(); var dir = new DirectoryInfo(file); request.Name = dir.Name; using (var sr = new StreamReader(Path.Combine(file, "description.txt"))) { string line; while ((line = sr.ReadLine()) != null) { request.Description += line + " \n"; } } using (StreamReader sr = new StreamReader(Path.Combine(file, "properties.txt"))) { string line; while ((line = sr.ReadLine()) != null) { string[] prop = line.Split(':'); request.Properties.Add(prop[0], prop[1]); } } request.IsCode = false; request.IsResponse = false; using (StreamReader sr = new StreamReader(Path.Combine(file, "format.txt"))) { string line; while ((line = sr.ReadLine()) != null) { request.Format = line; } } _requests.Add(request); } filetype = @"Response\"; var respDirectories = Directory.GetDirectories(Path.Combine(filepath, filetype)); foreach (var file in respDirectories) { var response = new ServiceObject(); var dir = new DirectoryInfo(file); response.Name = dir.Name; using (var sr = new StreamReader(Path.Combine(file, "description.txt"))) { string line; while ((line = sr.ReadLine()) != null) { response.Description += line + " \n"; } } using (var sr = new StreamReader(Path.Combine(file, "properties.txt"))) { string line; while ((line = sr.ReadLine()) != null) { var prop = line.Split(':'); response.Properties.Add(prop[0], prop[1]); } } response.IsCode = false; response.IsResponse = true; using (var sr = new StreamReader(Path.Combine(file, "format.txt"))) { string line; while ((line = sr.ReadLine()) != null) { response.Format = line; } } _responses.Add(response); } filetype = @"Methods\"; var methodDirectories = Directory.GetDirectories(Path.Combine(filepath, filetype)); foreach (var file in methodDirectories) { var method = new WebMethod(); var dir = new DirectoryInfo(file); method.Name = dir.Name; using (var sr = new StreamReader(Path.Combine(file, "description.txt"))) { string line; while ((line = sr.ReadLine()) != null) { method.Description += line; } } if (File.Exists(Path.Combine(file, "code.txt"))) { method.IsCode = File.Exists(Path.Combine(file, "code.txt")); using (var sr = new StreamReader(Path.Combine(file, "code.txt"))) { string line; while ((line = sr.ReadLine()) != null) { method.Code += line; } } } using (var sr = new StreamReader(Path.Combine(file, "properties.txt"))) { string line; while ((line = sr.ReadLine()) != null) { string[] prop = line.Split(':'); method.Parameters.Add(prop[0], prop[1]); } } using (var sr = new StreamReader(Path.Combine(file, "respreq.txt"))) { string line; while ((line = sr.ReadLine()) != null) { var prop = line.Split(':'); method.Request = prop[0]; method.Response = prop[1]; } } using (var sr = new StreamReader(Path.Combine(file, "format.txt"))) { string line; while ((line = sr.ReadLine()) != null) { method.Format = line; } } method.Screenshot = File.Exists(Path.Combine(file, "screen.png")); _methods.Add(method); } } catch (Exception) { Console.WriteLine("Error"); throw; } }
/// <summary> /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an /// <see cref="OAuthWebQuery" /> for the purpose of exchanging a request token /// for an access token authorized by the user at the Service Provider site. /// </summary> /// <param name="method">The HTTP method for the intended request</param> /// <seealso cref="http://oauth.net/core/1.0#anchor9"/> public virtual OAuthWebQueryInfo BuildAccessTokenInfo(WebMethod method) { return BuildAccessTokenInfo(method, null); }
public WebQuery GetQueryFor(string url, WebParameterCollection parameters, IWebQueryInfo info, WebMethod method, bool enableTrace) { return GetQueryForImpl(info, enableTrace); }
private void WithHammock <T>(IRestClient restClient, WebMethod method, Action <T, TwitterResponse> action, string path, params object[] segments) where T : class { WithHammock(restClient, method, action, ResolveUrlSegments(path, segments.ToList())); }
public async static Task<Result<string>> Call(string url, WebMethod method = WebMethod.Post, string contentType = null, Dictionary<string, string> post = null, string headerAccept = null, Dictionary<string, string> headers = null, Encoding encoding = null, string authorizationScheme = null, string authorizationToken = null) { Console.WriteLine(url); try { using (var client = new HttpClient()) { if (!string.IsNullOrEmpty(headerAccept)) { client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue(headerAccept)); } if (headers != null) { foreach (var header in headers) { client.DefaultRequestHeaders.TryAddWithoutValidation(header.Key, header.Value); } } if (!string.IsNullOrEmpty(authorizationScheme)) { if (!string.IsNullOrEmpty(authorizationToken)) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authorizationScheme, authorizationToken); } else { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authorizationScheme); } } if (method == WebMethod.Post) { if (null != post) { var content = new FormUrlEncodedContent(post); var response = await client.PostAsync(url, content); return Result.OkResultT(await response.Content.ReadAsStringAsync()); } } if (method == WebMethod.Get) { if (null != encoding) { var bytes = await client.GetByteArrayAsync(url); return Result.OkResultT(encoding.GetString(bytes)); } else { return Result.OkResultT(await client.GetStringAsync(url)); } } if (method == WebMethod.Delete) { var response = await client.DeleteAsync(url); return Result.OkResultT(response.ReasonPhrase); } if (method == WebMethod.Put) { if (null != post) { var content = new FormUrlEncodedContent(post); var response = await client.PutAsync(url, content); return Result.OkResultT(await response.Content.ReadAsStringAsync()); } } } } catch (Exception ex) { return Result.KoResultT<string>(ex.Message); } return Result.KoResultT<string>("Undefined case"); }
public WebQuery GetQueryFor(string url, WebParameterCollection parameters, IWebQueryInfo info, WebMethod method, bool enableTrace) { return(GetQueryForImpl(info, enableTrace)); }