Skip to content

Instantly share code, notes, and snippets.

@manrueda manrueda/Example.cs
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.