Created
November 7, 2016 22:31
-
-
Save Morgma/5e04f4732de4efa22ddc3804afd3c5e7 to your computer and use it in GitHub Desktop.
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
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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&