private static HttpRequestInfo CreateHttpRequestInfo(HttpDeliveryMethods scheme, IDictionary <string, string> fields) { var requestUri = new UriBuilder(MessagingTestBase.DefaultUrlForHttpRequestInfo); var headers = new NameValueCollection(); NameValueCollection form = null; string method; switch (scheme) { case HttpDeliveryMethods.PostRequest: method = "POST"; form = fields.ToNameValueCollection(); headers.Add(HttpRequestHeaders.ContentType, Channel.HttpFormUrlEncoded); break; case HttpDeliveryMethods.GetRequest: method = "GET"; requestUri.Query = MessagingUtilities.CreateQueryString(fields); break; case HttpDeliveryMethods.AuthorizationHeaderRequest: method = "GET"; headers.Add(HttpRequestHeaders.Authorization, CreateAuthorizationHeader(fields)); break; default: throw new ArgumentOutOfRangeException("scheme", scheme, "Unexpected value"); } return(new HttpRequestInfo(method, requestUri.Uri, form: form, headers: headers)); }
public static string GetString(string command, IDictionary <string, string> parameters = null, User user = null) { string _url = "http://api.exmo.com/v1/{0}"; var wb = new WebClient(); byte[] response; if (parameters != null && user != null) { parameters.Add("nonce", Convert.ToString(_nounce++)); var message = ToQueryString(parameters); var sign = Sign(user.secret, message); wb.Headers.Add("Sign", sign); wb.Headers.Add("Key", user.key); var data = parameters.ToNameValueCollection(); response = wb.UploadValues(string.Format(_url, command), "POST", data); return(Encoding.UTF8.GetString(response)); } else { response = wb.DownloadData(string.Format(_url, command)); } return(Encoding.UTF8.GetString(response)); }
/// <summary> /// Gets the parameters as a collection of name/value pairs. /// </summary> /// <param name="parameters">The parameters.</param> /// <returns> /// Returns an instance of <see cref="System.Collections.Specialized.NameValueCollection"/> with an /// additional entry for f=json. /// </returns> private NameValueCollection GetParametersAsNVC(IDictionary <string, string> parameters) { var nvc = parameters.ToNameValueCollection <string, string>(); nvc.Add("f", "json"); return(nvc); }
/// <summary> /// Sets a cookie /// </summary> /// <param name="cookieName">Cookie name</param> /// <param name="cookieValues">Cookie values</param> /// <param name="expires">Expiration time</param> /// <param name="httpOnly">A item indicating whether must mark like HttpOnly</param> public static void SetCookie(string cookieName, IDictionary <string, string> cookieValues, TimeSpan expires, bool httpOnly) { try { HttpCookie cookie = null; NameValueCollection values = cookieValues.ToNameValueCollection(); if (HttpContext.Current.Request.Cookies[cookieName] == null) { cookie = new HttpCookie(cookieName); } else { cookie = HttpContext.Current.Request.Cookies[cookieName]; } cookie.HttpOnly = httpOnly; cookie.Values.Clear(); cookie.Values.Add(values); if (expires != null && expires != TimeSpan.Zero) { DateTime actualDate = DateTime.UtcNow; cookie.Expires = actualDate.Add(expires); } HttpContext.Current.Response.Cookies.Remove(cookieName); HttpContext.Current.Response.Cookies.Add(cookie); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
// Token: 0x060001CC RID: 460 RVA: 0x0000798C File Offset: 0x00005B8C private string ApiQuery(string apiName, IDictionary <string, string> req, string Method = "POST") { string text = ((int)Math.Round(DateTime.Now.Subtract(new DateTime(2018, 1, 1)).TotalSeconds * 100.0)).ToString(); string result; using (HttpRequest httpRequest = new HttpRequest()) { string text2 = LivecoinAPI.http_build_query(this.ToQueryString(req)); string text3 = LivecoinAPI.HashHMAC(this._privateKey, text2).ToUpper(); httpRequest.IgnoreProtocolErrors = true; httpRequest.AddHeader("Sign", text3); httpRequest.AddHeader("Api-Key", this._publicKey); NameValueCollection nameValueCollection = req.ToNameValueCollection <string, string>(); string text4 = string.Empty; bool flag = Method == "POST"; if (flag) { text4 = httpRequest.Post(this._baseAdress + apiName, text2, "application/x-www-form-urlencoded").ToString(); } else { bool flag2 = !string.IsNullOrWhiteSpace(text2); if (flag2) { text4 = httpRequest.Get(this._baseAdress + apiName + "?" + text2, null).ToString(); } else { text4 = httpRequest.Get(this._baseAdress + apiName, null).ToString(); } } result = text4; } return(result); }
public void IDictionaryTest_ToNameValueCollection_002() { IDictionary <string, string> dict = null; var actual = dict.ToNameValueCollection(); Assert.IsNull(actual); }
public CefSharpResponse(Stream content, string mime, string reasonPhrase, int statusCode, IDictionary <string, string> headers) { Content = content; Mime = mime; ReasonPhrase = reasonPhrase; StatusCode = statusCode; Headers = headers.ToNameValueCollection(); }
public IDictionary<string, string> SendDirectMessageAndGetResponse(ServiceEndpoint providerEndpoint, IDictionary<string, string> fields) { OpenIdProvider provider = new OpenIdProvider(providerStore, providerEndpoint.ProviderEndpoint, providerEndpoint.ProviderEndpoint, fields.ToNameValueCollection()); Debug.Assert(provider.Request.IsResponseReady, "Direct messages should always have an immediately available response."); Response webResponse = (Response)provider.Request.Response; EncodableResponse opAuthResponse = (EncodableResponse)webResponse.EncodableMessage; return opAuthResponse.EncodedFields; }
public string ApiQuery(string apiName, IDictionary <string, string> req, string tradeCouples = null, int?limit = null) { try { lock (_queryHttpLocker) { _rateGate.WaitToProceed(); using (var wb = new WebClient()) { req.Add("nonce", Convert.ToString(_nounce++)); if (limit != null) { req.Add("limit", limit.ToString()); } if (tradeCouples != null) { req.Add("pair", tradeCouples); } var message = ToQueryString(req); var sign = Sign(_secret, message); wb.Headers.Add("Sign", sign); wb.Headers.Add("Key", _key); var data = req.ToNameValueCollection(); //var response = wb.UploadValues(string.Format(_url, apiName), "POST", data); byte[] response; response = wb.UploadValues(_url + apiName + "//", "POST", data); return(Encoding.UTF8.GetString(response)); } } } catch (Exception e) { SendLogMessage(e.ToString(), LogMessageType.Error); IsConnected = false; if (Disconnected != null) { Disconnected(); } return(""); } }
private void Upload(Uri uri, HttpMethod method, IDictionary <string, string> data = null) { if (uri == null) { throw new ArgumentNullException("uri"); } using (Client client = CreateClient(uri, method, data)) { client.UploadValues(uri, method.ToString(), data.ToNameValueCollection()); } }
private T Upload <T>(Uri uri, HttpMethod method, Func <string, T> serializer, IDictionary <string, string> data = null) { if (uri == null) { throw new ArgumentNullException("uri"); } using (Client client = CreateClient(uri, method, data)) { byte[] response = client.UploadValues(uri, method.ToString(), data.ToNameValueCollection()); return(serializer(Encoding.UTF8.GetString(response))); } }
private static string BuildEndpoint(string endpoint, IDictionary <string, string> args) { string path = endpoint; if (args.Count != 0) { var query = HttpUtility.ParseQueryString(string.Empty); query.Add(args.ToNameValueCollection()); path = string.Format("{0}?{1}", endpoint, query.ToString()); } return(path); }
public T Get <T>(Uri uri, Func <string, T> serializer, IDictionary <string, string> data = null) { if (uri == null) { throw new ArgumentNullException("uri"); } using (Client client = CreateClient(uri, HttpMethod.Get, data)) { client.QueryString.Add(data.ToNameValueCollection()); return(serializer(client.DownloadString(uri))); } }
public override Result Read(string table, IDictionary<string, string> query) { var type = ResolveModelType(table); var param = query.ToNameValueCollection(); var database = GetDatabase(); var collection = database.GetCollection(ResolveModelType(table), table); var result = collection.FindAllAs(type); var data = Filter(result, type, param); return new Result { Success = true, Data = data }; }
internal static HttpRequestInfo CreateHttpRequestInfo(string method, IDictionary<string, string> fields) { var requestUri = new UriBuilder(DefaultUrlForHttpRequestInfo); var headers = new NameValueCollection(); NameValueCollection form = null; if (method == "POST") { form = fields.ToNameValueCollection(); headers.Add(HttpRequestHeaders.ContentType, Channel.HttpFormUrlEncoded); } else if (method == "GET") { requestUri.Query = MessagingUtilities.CreateQueryString(fields); } else { throw new ArgumentOutOfRangeException("method", method, "Expected POST or GET"); } return new HttpRequestInfo(method, requestUri.Uri, form: form, headers: headers); }
public string ApiQuery(string apiName, IDictionary <string, string> req) { using var wb = new WebClient(); req.AddNonceParameter(); var message = req.ToQueryString(); var sign = Sign(_secret, message); wb.Headers.Add("Sign", sign); wb.Headers.Add("Key", _key); var data = req.ToNameValueCollection(); var response = wb.UploadValues($"{_url}/{apiName}", HttpMethod.Post.ToString(), data); return(Encoding.UTF8.GetString(response)); }
public string ApiQuery(string apiName, IDictionary <string, string> req) { using (var wb = new WebClient()) { req.Add("nonce", Convert.ToString(_nounce++)); var message = ToQueryString(req); var sign = Sign(_secret, message); wb.Headers.Add("Sign", sign); wb.Headers.Add("Key", _key); var data = req.ToNameValueCollection(); var response = wb.UploadValues(string.Format(_url, apiName), "POST", data); return(Encoding.UTF8.GetString(response)); } }
// Token: 0x060000D6 RID: 214 RVA: 0x000062B4 File Offset: 0x000044B4 private string ApiQuery(string apiName, IDictionary <string, string> req) { string value = ((int)Math.Round(DateTime.Now.Subtract(new DateTime(2018, 1, 1)).TotalSeconds * 100.0)).ToString(); string @string; using (WebClient webClient = new WebClient()) { req.Add("nonce", value); req.Add("method", apiName); string message = this.ToQueryString(req); string value2 = base.Sign(this._privateKey, message); webClient.Headers.Add("Sign", value2); webClient.Headers.Add("Key", this._publicKey); NameValueCollection data = req.ToNameValueCollection <string, string>(); byte[] bytes = webClient.UploadValues(this._baseAdress, "POST", data); @string = Encoding.UTF8.GetString(bytes); } return(@string); }
// Token: 0x060000E1 RID: 225 RVA: 0x00006650 File Offset: 0x00004850 private string ApiQuery(string apiName, IDictionary <string, string> req) { string @string; using (WebClient webClient = new WebClient()) { string key = "nonce"; long nounce = this._nounce; this._nounce = nounce + 1L; req.Add(key, Convert.ToString(nounce)); string message = this.ToQueryString(req); string value = base.Sign(this._privateKey, message); webClient.Headers.Add("Sign", value); webClient.Headers.Add("Key", this._publicKey); NameValueCollection data = req.ToNameValueCollection <string, string>(); byte[] bytes = webClient.UploadValues(string.Format(this._baseAdress, apiName), "POST", data); @string = Encoding.UTF8.GetString(bytes); } return(@string); }
public string ApiQuery(string apiName, IDictionary <string, string> req, string tradeCouples = null, int?limit = null) { using (var wb = new WebClient()) { req.Add("nonce", Convert.ToString(_nounce++)); var message = ToQueryString(req); var sign = Sign(_secret, message); wb.Headers.Add("Sign", sign); wb.Headers.Add("Key", _key); var data = req.ToNameValueCollection(); //var response = wb.UploadValues(string.Format(_url, apiName), "POST", data); byte[] response; if (limit == null) { if (tradeCouples != null) { string tmp = string.Format(_urlPublicAPI, apiName, tradeCouples); response = wb.UploadValues(tmp, "POST", data); } else { response = wb.UploadValues(string.Format(_url, apiName), "POST", data); } } else { if (tradeCouples != null) { response = wb.UploadValues(string.Format(_urlPublicAPIwithLimit, apiName, tradeCouples, limit.ToString()), "POST", data); } else { response = wb.UploadValues(string.Format(_url, apiName), "POST", data); } } return(Encoding.UTF8.GetString(response)); } }
internal static HttpRequestInfo CreateHttpRequestInfo(string method, IDictionary <string, string> fields) { var requestUri = new UriBuilder(DefaultUrlForHttpRequestInfo); var headers = new NameValueCollection(); NameValueCollection form = null; if (method == "POST") { form = fields.ToNameValueCollection(); headers.Add(HttpRequestHeaders.ContentType, Channel.HttpFormUrlEncoded); } else if (method == "GET") { requestUri.Query = MessagingUtilities.CreateQueryString(fields); } else { throw new ArgumentOutOfRangeException("method", method, "Expected POST or GET"); } return(new HttpRequestInfo(method, requestUri.Uri, form: form, headers: headers)); }
/// <summary> /// POSTs to an API URL and returns a dynamically typed object representing the /// response from the service. /// </summary> /// <param name="pageMethod">Page, method, or file to append to end of API URL</param> /// <param name="formData">String dictionary of Key/value pair query parameters (e.g. ?key=value)</param> /// <returns></returns> public dynamic Post(string pageMethod, IDictionary<string, string> formData) { return PerformRequest(pageMethod, HttpMethod.POST, formData.ToNameValueCollection()); }
/// <summary> /// Converts the specified <paramref name="form"/> into its <see cref="string"/> equivalent. /// </summary> /// <param name="form">The form-data values to convert.</param> /// <returns>A <see cref="string"/> equivalent to the values in the <paramref name="form"/>.</returns> public static string FromDictionary(IDictionary <string, string[]> form) { Validator.ThrowIfNull(form, nameof(form)); return(FromNameValueCollection(form.ToNameValueCollection())); }
/// <summary> /// GETs from API URL and returns a dynamically typed object representing the /// response from the service. /// </summary> /// <param name="pageMethod">Page, method, or file to append to end of API URL</param> /// <param name="queryParams">String dictionary of Key/value pair query parameters (e.g. ?key=value)</param> /// <returns></returns> public dynamic Get(string pageMethod, IDictionary <string, string> queryParams) { return(PerformRequest(pageMethod, HttpMethod.GET, queryParams.ToNameValueCollection())); }
public IDictionary <string, string> SendDirectMessageAndGetResponse(ServiceEndpoint providerEndpoint, IDictionary <string, string> fields) { OpenIdProvider provider = new OpenIdProvider(providerStore, providerEndpoint.ProviderEndpoint, providerEndpoint.ProviderEndpoint, fields.ToNameValueCollection()); Debug.Assert(provider.Request.IsResponseReady, "Direct messages should always have an immediately available response."); Response webResponse = (Response)provider.Request.Response; EncodableResponse opAuthResponse = (EncodableResponse)webResponse.EncodableMessage; return(opAuthResponse.EncodedFields); }
/// <summary> /// Converts the specified <paramref name="headers"/> into its <see cref="string"/> equivalent. /// </summary> /// <param name="headers">The request-header values to convert.</param> /// <returns>A <see cref="string"/> equivalent to the values in the <paramref name="headers"/>.</returns> public static string FromDictionary(IDictionary <string, string[]> headers) { Validator.ThrowIfNull(headers, nameof(headers)); return(FromNameValueCollection(headers.ToNameValueCollection())); }
public static void InjectDependencies <T>( this T controller, IDictionary <string, string> querystringValues, IDictionary <string, string> formValues, IBackOfficeRequestContext backOfficeRequest, bool ensureModelStateError = true, bool noExecution = false, string userName = "******", string[] userRoles = null) where T : Controller { var routeData = new RouteData(); //we need to mock the dependency resolver for the IBackOfficeRequest context //because of how the RebelAuthorizationAttribute works var dependencyResolver = Substitute.For <IDependencyResolver>(); DependencyResolver.SetResolver(dependencyResolver); dependencyResolver.GetService(typeof(IBackOfficeRequestContext)).Returns(backOfficeRequest); var ctx = new FakeHttpContextFactory("~/MyController/MyAction/MyId"); controller.Url = new UrlHelper(ctx.RequestContext); controller.ValueProvider = formValues.ToValueProvider(); var context = new ControllerContext(ctx.RequestContext, controller) { RouteData = routeData }; controller.ControllerContext = context; //set the form values controller.HttpContext.Request.Stub(x => x.QueryString).Return(formValues.ToNameValueCollection()); controller.HttpContext.Request.Stub(x => x.Form).Return(formValues.ToNameValueCollection()); controller.HttpContext.Request.Stub(x => x.RequestType).Return(formValues.Count > 0 ? "POST" : "GET"); if (userRoles == null) { userRoles = new string[] { "administrator" } } ; //default to administrator var userData = new UserData() { Id = Guid.NewGuid().ToString("N"), AllowedApplications = new string[] {}, Username = userName, RealName = userName, Roles = userRoles, SessionTimeout = 0, StartContentNode = "-1", StartMediaNode = "-1" }; controller.HttpContext.Stub(x => x.User).Return(new FakePrincipal(new RebelBackOfficeIdentity(new FormsAuthenticationTicket(4, userName, DateTime.Now, DateTime.Now.AddDays(1), false, (new JavaScriptSerializer()).Serialize(userData))), userRoles)); if (!noExecution) { //if Initialize needs to run on the controller, this needs to occur, so we'll swallow the exception cuz there will always be one. try { (controller as IController).Execute(ctx.RequestContext); } catch (System.Exception) { } } if (ensureModelStateError) { //always ensure invalid model state so we can get the model returned controller.ModelState.AddModelError("DummyKey", "error"); } }
private JToken CallMethod(string methodName, IDictionary <string, string> parameters) { JToken result; if (_token != null) { parameters.Add("access_token", _token); } using (var web = new WebClient()) { result = JToken.Parse(Encoding.UTF8.GetString(web.UploadValues($"https://monopoly-one.com/api/{methodName}", parameters.ToNameValueCollection()))); } if (result["code"].ToObject <int>() != 0) { throw new Exception(result["description"].ToObject <string>()); } return(result["data"]); }
/// <summary> /// Converts the specified <paramref name="query"/> into its <see cref="string"/> equivalent. /// </summary> /// <param name="query">The query string values to convert.</param> /// <param name="urlEncode">Specify <c>true</c> to encode the <paramref name="query"/> into a URL-encoded string; otherwise, <c>false</c>.</param> /// <returns>A <see cref="string"/> equivalent to the values in the <paramref name="query"/>.</returns> public static string FromDictionary(IDictionary <string, string[]> query, bool urlEncode) { Validator.ThrowIfNull(query, nameof(query)); return(FromNameValueCollection(query.ToNameValueCollection(), urlEncode)); }
/// <summary> /// POSTs to an API URL and returns a dynamically typed object representing the /// response from the service. /// </summary> /// <param name="pageMethod">Page, method, or file to append to end of API URL</param> /// <param name="formData">String dictionary of Key/value pair query parameters (e.g. ?key=value)</param> /// <returns></returns> public dynamic Post(string pageMethod, IDictionary <string, string> formData) { return(PerformRequest(pageMethod, HttpMethod.POST, formData.ToNameValueCollection())); }
private static HttpRequestInfo CreateHttpRequestInfo(HttpDeliveryMethods scheme, IDictionary<string, string> fields) { var requestUri = new UriBuilder(MessagingTestBase.DefaultUrlForHttpRequestInfo); var headers = new NameValueCollection(); NameValueCollection form = null; string method; switch (scheme) { case HttpDeliveryMethods.PostRequest: method = "POST"; form = fields.ToNameValueCollection(); headers.Add(HttpRequestHeaders.ContentType, Channel.HttpFormUrlEncoded); break; case HttpDeliveryMethods.GetRequest: method = "GET"; requestUri.Query = MessagingUtilities.CreateQueryString(fields); break; case HttpDeliveryMethods.AuthorizationHeaderRequest: method = "GET"; headers.Add(HttpRequestHeaders.Authorization, CreateAuthorizationHeader(fields)); break; default: throw new ArgumentOutOfRangeException("scheme", scheme, "Unexpected value"); } return new HttpRequestInfo(method, requestUri.Uri, form: form, headers: headers); }
/// <summary> /// GETs from API URL and returns a dynamically typed object representing the /// response from the service. /// </summary> /// <param name="pageMethod">Page, method, or file to append to end of API URL</param> /// <param name="queryParams">String dictionary of Key/value pair query parameters (e.g. ?key=value)</param> /// <returns></returns> public dynamic Get(string pageMethod, IDictionary<string, string> queryParams) { return PerformRequest(pageMethod, HttpMethod.GET, queryParams.ToNameValueCollection()); }