Skip to content

Instantly share code, notes, and snippets.

@Morgma
Created November 7, 2016 22:31
Show Gist options
  • Save Morgma/5e04f4732de4efa22ddc3804afd3c5e7 to your computer and use it in GitHub Desktop.
Save Morgma/5e04f4732de4efa22ddc3804afd3c5e7 to your computer and use it in GitHub Desktop.
public class ProxyController : ApiController
{
[HttpGet, HttpPost]
[Route("proxy/call")]
public async Task<HttpResponseMessage> ProxyCall(string uri)
{
var queryString = "";
var requestQuery = Request.GetQueryNameValuePairs();
var qparams = requestQuery as KeyValuePair<string, string>[] ?? requestQuery.ToArray();
for (int i = 1; i <= qparams.Count() - 1; i++)
{
if (string.IsNullOrEmpty(qparams[i].Key))
continue;
var key = HttpUtility.UrlEncode(qparams[i].Key);
var value = HttpUtility.UrlEncode(qparams[i].Value);
queryString += ((i == 1) ? "?" : "&") + $"{key}={value}";
}
var requestUri = new Uri(uri);
requestUri = new Uri(requestUri.AbsoluteUri + queryString);
using (var handler = new WebRequestHandler())
{
handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
HttpResponseMessage response;
Request.RequestUri = requestUri;
if (Request.Method != HttpMethod.Post)
{
Request.Content = null;
}
using (HttpClient client = new HttpClient(handler))
{
response = await client.SendAsync(Request, HttpCompletionOption.ResponseContentRead);
}
return response;
}
}
}
@Morgma
Copy link
Author

Morgma commented Nov 7, 2016

Toying around with a basic forwarder to supplement Lead Forensics tracking call which does not support embedding into HTTPS sites.

@Morgma
Copy link
Author

Morgma commented Nov 7, 2016

Example usage for the Lead Forensics Js call to the HTTP tracker endpoint from my HTTPS enabled site:
var link = document.location.href + '/proxy/call?uri=http://www.66-trk-srv.com/Track/Capture.aspx&retType=js&

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment