Passing Headers Code
httpWebRequest.aspx
1 2 | <%@ Control Language="vb" AutoEventWireup="false" Codebehind="httpWebRequest.ascx.vb" Inherits="DamianM.httpWebRequest1" %> <asp:Literal id="Literal1" runat="server"></asp:Literal> |
httpWebRequest.aspx.vb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | Public Class httpWebRequest1 Inherits System.Web.UI.UserControl Protected WithEvents Literal1 As System.Web.UI.WebControls.Literal Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim req As System.Net.HttpWebRequest Dim res As System.Net.HttpWebResponse Dim sr As System.IO.StreamReader '--notice that the instance is created using webrequest '--this is what microsoft recomends req = System.Net.WebRequest.Create("http://www.damianm.co.uk/code/4/page.aspx") res = req.GetResponse() 'read in the page sr = New System.IO.StreamReader(res.GetResponseStream()) Literal1.Text = sr.ReadToEnd '--tidy up sr.Close() res.Close() End Sub End Class |
Webclient.aspx
1 2 | <%@ Control Language="vb" AutoEventWireup="false" Codebehind="Webclient.ascx.vb" Inherits="DamianM.Webclient1" %> <asp:Literal id="Literal1" runat="server"></asp:Literal> |
Webclient.aspx.vb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | Public Class Webclient1 Inherits System.Web.UI.UserControl Protected WithEvents Literal1 As System.Web.UI.WebControls.Literal Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim wc As New System.Net.WebClient() Dim s As System.IO.Stream Dim sr As System.IO.StreamReader s = wc.OpenRead("http://www.damianm.co.uk/code/4/page.aspx") 'read in the page sr = New System.IO.StreamReader(s) Literal1.Text = sr.ReadToEnd() '--tidy up sr.Close() s.Close() End Sub End Class |



















