C# Can I return HttpWebResponse result to iframe - Uses Digest authentication

Posted by chadsxe on Stack Overflow See other posts from Stack Overflow or by chadsxe
Published on 2013-10-21T15:51:56Z Indexed on 2013/10/21 15:53 UTC
Read the original article Hit count: 1064

I am trying to figure out a way to display a cross-domain web page that uses Digest Authentication. My initial thought was to make a web request and return the entire page source. I currently have no issues with authenticating and getting a response but I am not sure how to properly return the needed data.

        // Create a request for the URL. 
        WebRequest request = WebRequest.Create("http://some-url/cgi/image.php?type=live");

        // Set the credentials.
        request.Credentials = new NetworkCredential(username, password);
        // Get the response.
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        // Get the stream containing content returned by the server.
        Stream dataStream = response.GetResponseStream();
        // Open the stream using a StreamReader for easy access.
        StreamReader reader = new StreamReader(dataStream);
        // Read the content.
        string responseFromServer = reader.ReadToEnd();

        // Clean up the streams and the response.
        reader.Close();
        dataStream.Close();
        response.Close();

        return responseFromServer;

My problems are currently...

  • responseFromServer is not returning the entire source of the page. I.E. missing body and head tags
  • The data is encoded improperly in responseFromServer. I believe this has something to do with the transfer encoding being of the type chunked.

Further more...

  • I am not entirely sure if this is even possible.

If it matters, this is being done in ASP.NET MVC 4 C#.

Thanks,

Chad

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-mvc-4