Last active
August 29, 2015 14:26
-
-
Save manrueda/b6c902865ee641ebc464 to your computer and use it in GitHub Desktop.
Request Piper
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
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); | |
} | |
} | |
} | |
} |
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
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