Skip to content

Instantly share code, notes, and snippets.

@manrueda
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manrueda/b6c902865ee641ebc464 to your computer and use it in GitHub Desktop.
Save manrueda/b6c902865ee641ebc464 to your computer and use it in GitHub Desktop.
Request Piper
using System;
using System.Collections.Generic;
using System.Net;
using System.Web.Mvc;
namespace MySite.Controllers
{
public class ServersController : Controller
{
[HttpGet()]
public ActionResult Index()
{
return View("Index");
}
[HttpGet()]
public void getGraph(string site)
{
using (HttpWebResponse req = RequestPiper.Get(site)) {
System.Web.HttpContext.Current.Response.Pipe(req);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Net.Http;
using System.IO;
namespace RequestPiper
{
public static class RequestPiper
{
public static HttpWebResponse Get(string url)
{
var req = HttpWebRequest.Create(url);
req.Method = "GET";
return (HttpWebResponse)req.GetResponse();
}
public static void Pipe(this HttpResponse Response, HttpWebResponse getResponse, bool autoEnd = false)
{
Response.ContentType = getResponse.ContentType;
using (Stream dataStream = getResponse.GetResponseStream())
{
dataStream.CopyTo(Response.OutputStream);
if (autoEnd)
Response.End();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment