-
-
Save mahizsas/d298c48cd65ccc7882d3 to your computer and use it in GitHub Desktop.
HttpHandler that act as a proxy
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 ProxyHandler : IHttpHandler | |
{ | |
const string SERVER_URL = "http://dev-server"; | |
#region IHttpHandler Members | |
public bool IsReusable | |
{ | |
get { return false; } | |
} | |
public void ProcessRequest(HttpContext context) | |
{ | |
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(SERVER_URL + context.Request.Url.PathAndQuery); | |
webRequest.Method = context.Request.HttpMethod; | |
webRequest.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; | |
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse(); | |
context.Response.StatusCode = (int)response.StatusCode; | |
context.Response.Status = string.Format("{0} {1}", (int)response.StatusCode, response.StatusCode); | |
context.Response.ContentType = response.ContentType; | |
context.Response.Write(new StreamReader(response.GetResponseStream()).ReadToEnd()); | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment