public static string QueryStringForTR(Request trParams, Request req, string postURL, BraintreeService service) { #if netcore string trData = TrUtil.BuildTrData(trParams, "http://example.com", service); string postData = "tr_data=" + WebUtility.UrlEncode(trData) + "&"; postData += req.ToQueryString(); var request = new HttpRequestMessage(new HttpMethod("POST"), postURL); request.Headers.Add("KeepAlive", "false"); request.Headers.Add("Accept", "application/json"); byte[] buffer = Encoding.UTF8.GetBytes(postData); request.Content = new StringContent(postData, Encoding.UTF8, "application/x-www-form-urlencoded"); request.Content.Headers.Add("Content-Length", buffer.Length.ToString()); var httpClientHandler = new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, AllowAutoRedirect = false, }; HttpResponseMessage response; using (var client = new HttpClient(httpClientHandler)) { response = client.SendAsync(request).GetAwaiter().GetResult(); } StreamReader reader = new StreamReader(response.Content.ReadAsStreamAsync().Result, Encoding.UTF8); string responseBody = reader.ReadToEnd(); string query = response.Headers.Location.Query; return query; #else string trData = TrUtil.BuildTrData(trParams, "http://example.com", service); string postData = "tr_data=" + HttpUtility.UrlEncode(trData, Encoding.UTF8) + "&"; postData += req.ToQueryString(); var request = WebRequest.Create(postURL) as HttpWebRequest; request.Method = "POST"; request.KeepAlive = false; request.AllowAutoRedirect = false; byte[] buffer = Encoding.UTF8.GetBytes(postData); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = buffer.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(buffer, 0, buffer.Length); requestStream.Close(); var response = request.GetResponse() as HttpWebResponse; string query = new Uri(response.GetResponseHeader("Location")).Query; response.Close(); return query; #endif }
public static string BuildTrData(Request request, string redirectURL, BraintreeService service) { var dateString = DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmmss"); var trContent = new QueryString(). Append("api_version", service.ApiVersion). Append("public_key", service.PublicKey). Append("redirect_url", redirectURL). Append("time", dateString). Append("kind", request.Kind()). ToString(); string requestQueryString = request.ToQueryString(); if (requestQueryString.Length > 0) { trContent += "&" + requestQueryString; } var signatureService = new SignatureService { Key = service.PrivateKey, Hasher = new Sha1Hasher() }; return signatureService.Sign(trContent); }
public static string BuildTrData(Request request, string redirectURL, BraintreeService service) { var dateString = DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmmss"); var trContent = new QueryString(). Append("api_version", service.ApiVersion). Append("public_key", service.PublicKey). Append("redirect_url", redirectURL). Append("time", dateString). Append("kind", request.Kind()). ToString(); string requestQueryString = request.ToQueryString(); if (requestQueryString.Length > 0) { trContent += "&" + requestQueryString; } var signatureService = new SignatureService { Key = service.PrivateKey, Hasher = new Sha1Hasher() }; return(signatureService.Sign(trContent)); }
public static string QueryStringForTR(Request trParams, Request req, string postURL, BraintreeService service) { string trData = TrUtil.BuildTrData(trParams, "http://example.com", service); string postData = "tr_data=" + HttpUtility.UrlEncode(trData, Encoding.UTF8) + "&"; postData += req.ToQueryString(); var request = WebRequest.Create(postURL) as HttpWebRequest; request.Method = "POST"; request.KeepAlive = false; request.AllowAutoRedirect = false; byte[] buffer = Encoding.UTF8.GetBytes(postData); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = buffer.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(buffer, 0, buffer.Length); requestStream.Close(); var response = request.GetResponse() as HttpWebResponse; string query = new Uri(response.GetResponseHeader("Location")).Query; response.Close(); return query; }
protected virtual QueryString AppendRequest(string parent, Request request) { if (request == null) { return this; } string requestQueryString = request.ToQueryString(parent); if (requestQueryString.Length > 0) { if (builder.Length > 0) { builder.Append("&"); } builder.Append(requestQueryString); } return this; }
protected virtual QueryString AppendRequest(string parent, Request request) { if (request == null) { return(this); } string requestQueryString = request.ToQueryString(parent); if (requestQueryString.Length > 0) { if (builder.Length > 0) { builder.Append("&"); } builder.Append(requestQueryString); } return(this); }
public static String BuildTrData(Request request, String redirectURL, BraintreeService service) { String dateString = DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmmss"); String trContent = new QueryString(). Append("api_version", service.ApiVersion). Append("public_key", service.PublicKey). Append("redirect_url", redirectURL). Append("time", dateString). Append("kind", request.Kind()). ToString(); String requestQueryString = request.ToQueryString(); if (requestQueryString.Length > 0) { trContent += "&" + requestQueryString; } String trHash = new Crypto().HmacHash(service.PrivateKey, trContent); return trHash + "|" + trContent; }