• The eternal confessions of a beautiful mind...
  • DamianM.Co.UK
  • Home
  • About
  • Archives
  • Contact
  • Sitemap
  • My Flickr

    IMG_9585IMG_9115IMG_9113IMG_9111IMG_9078IMG_9075IMG_9069IMG_9065IMG_9041IMG_9032IMG_8963IMG_8928IMG_8916IMG_8915IMG_8904IMG_8876IMG_8858IMG_8830IMG_8828IMG_8826

  • Recent Posts

    • New Ohio Roller Coaster - INSANE!!!
    • Speeding
    • Captions not required
    • Unfortunate Backgrounds
    • Unfortunate Signs
    • OMG!!
    • Women as explained by engineer
    • The Monty Hall Problem
    • ahhh still love them - Motivational Posters
    • What does Mona Lisa do when the Museum is closed………
    • 21st Century kids books
    • Cool Origami
    • AWESOME Pictures!
    • Things you shouldn’t find in your vegetable patch!
    • World’s Best Graffiti…?
  • My Tools

    • Blog_LinkIt
    • DCoda Theme
    • DCoda Widgets
    • RSS_Sticky
    • WordPress.org
    • WP_BlogNetworking
    • WP_BlogRollSync
    • WP_BoilerPlate
    • WP_Censor
    • WP_ContactMe
    • WP_DeliciousPost
    • WP_EasyReply
    • WP_HeadNFoot
    • WP_LinkIt
    • WP_OneInstall
    • WP_PostDate
    • WP_PostNotes
    • WP_RssSticky
    • WP_Spoiler
    • WP_Submission
  • My Web

    • ASPAlliance
    • ClaimID
    • del.ico.us
    • Digg
    • DSLRBlog
    • DVDProfiler
    • Flickr
    • Honeyed SPAM
    • My Blog
    • My company
    • MYSpace
    • WordPress.org
    • YouTube

    Posted Forms Code

    httpWebRequest.aspx

    1
    2
    
    <%@ Control Language="vb" AutoEventWireup="false" Codebehind="httpWebRequest.ascx.vb" Inherits="DamianM.httpWebRequest3" %>
    <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
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    
    Public Class httpWebRequest3
        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
            Dim s As System.IO.Stream
            Dim b As Byte()
     
     
            '--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.3/formreader.aspx")
     
            'enncode the form data string into a byte array
            b = System.Text.Encoding.ASCII.GetBytes("text=test text&password=secret&checkbox=on&textarea=a longer text sentence&submit=submit")
     
            'indicate that you will be posting the data
            req.Method = "post"
            req.ContentType = "application/x-www-form-urlencoded"
     
            'send the form
            req.ContentLength = b.Length
            s = req.GetRequestStream()
            s.Write(b, 0, b.Length)
            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.Webclient3" %>
    <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
    22
    23
    
    Public Class Webclient3
        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 b As Byte()
            Dim res As Byte()
     
            'enncode the form data string into a byte array
            b = System.Text.Encoding.ASCII.GetBytes("text=test text&password=secret&checkbox=on&textarea=a longer text sentence&submit=submit")
     
            'set the content type of the data
            wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
     
            'scrapte the data
            res = wc.UploadData("http://www.damianm.co.uk/code/4.3/formreader.aspx", b)
     
            'convert the return page from a byte array to ascii and display
            Literal1.Text = System.Text.Encoding.ASCII.GetString(res)
        End Sub
     
    End Class

    Leave a Reply

    Related Posts from the Past:

    • .NET Screen Scraping in depth
    • File uploading with .NET
    • Forms Code
    • Scraping in one line using temporary objects code
    • Me Code Monkey