Skip to content

Instantly share code, notes, and snippets.

@jviveiros
Created March 31, 2018 01:03
Show Gist options
  • Save jviveiros/1269c9b7bf19e122350747d83a10eed5 to your computer and use it in GitHub Desktop.
Save jviveiros/1269c9b7bf19e122350747d83a10eed5 to your computer and use it in GitHub Desktop.
C Sharp Example
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