Created
March 31, 2018 01:03
-
-
Save jviveiros/1269c9b7bf19e122350747d83a10eed5 to your computer and use it in GitHub Desktop.
C Sharp Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using Newtonsoft.Json.Linq; | |
using System.Net; | |
namespace example | |
{ | |
public static class Example | |
{ | |
private static readonly string Username = Environment.GetEnvironmentVariable("FORWARD_HTTP_PROXY_USERNAME"); | |
private static readonly string Password = Environment.GetEnvironmentVariable("FORWARD_HTTP_PROXY_PASSWORD"); | |
private static readonly string ForwardProxy = Environment.GetEnvironmentVariable("FORWARD_HTTP_PROXY_HOST"); | |
private static readonly string ReverseProxy = Environment.GetEnvironmentVariable("REVERSE_HTTP_PROXY_HOST"); | |
public static async Task<string> RevealViaForwardProxy(string redactData) | |
{ | |
var credentials = new NetworkCredential(Username, Password); | |
var proxy = new WebProxy(string.Format("http://{0}", ForwardProxy), false) | |
{ | |
UseDefaultCredentials = false, | |
Credentials = credentials, | |
}; | |
var handler = new HttpClientHandler() | |
{ | |
Proxy = proxy, | |
PreAuthenticate = true, | |
UseDefaultCredentials = false, | |
}; | |
var client = new HttpClient(handler); | |
var response = await client.PostAsync("https://httpbin.verygoodsecurity.io/post", new StringContent(redactData)); | |
var responseBody = await response.Content.ReadAsStringAsync(); | |
return JObject.Parse(responseBody)["data"].ToObject<string>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment