submit form using httpwebrequest

bhavin12300

Active member
Joined
Sep 18, 2007
Messages
44
Programming Experience
Beginner
hi expert.
i need bit help from you.
i am trying to submit webform on one site.it is aspx site.
In this form there is only one field in which i have to enter my email address and submit it.
i am able to achive following so far.
1)Using httpwebrequest i got the webpage with cookie maintain in cookiecontainer properly.

i have analyze the form and it is submitting __viewstate1 and other value from that form to action attribute of form.
i think i have success fully submitted my data to server but it is not responding the way it should.(like after submitting my email address it should send email to my account)
rather server response is same web form.(i think it is ok coz data to be submitted to same webform)but in response server should add my email address to its new response telling email is send to XXXYYY account.

i think i am missing to set some attribute in my httpwebrequest object.
can anyone help me please.
following is my code.
VB.NET:
Dim action As String
        Dim submit_data As String
        temp2 = htmldoc.getElementById("FileBuilding")
        action = temp2.getAttribute("action")
        submit_data = "__EVENTTARGET=" & event_target & "&"
        submit_data = submit_data & "__EVENTARGUMENT=" & event_arg & "&"
        submit_data = submit_data & "__VIEWSTATE1=" & view_source1 & "&"
        submit_data = submit_data & "__VIEWSTATE2=" & view_source2 & "&"
        submit_data = submit_data & "__VIEWSTATE3=" & view_source3 & "&"
        submit_data = submit_data & "__VIEWSTATE4=" & view_source4 & "&"
        submit_data = submit_data & "__VIEWSTATE0=" & view_source0 & "&"
        submit_data = submit_data & "__VIEWSTATE=" & view_source & "&"
        submit_data = submit_data & "__VIEWSTATE=" & view_source & "&"
        submit_data = submit_data & "topHeadMain:Textbox1=&"
        submit_data = submit_data & "txtEmailAddress=emailaddress@yahoo.com&"
        submit_data = submit_data & "btnSend=Send"


        Dim encodedPostData() As Byte
        encodedPostData = System.Text.Encoding.ASCII.GetBytes(submit_data)
        temp = System.Net.WebRequest.Create(action)
        temp.MaximumResponseHeadersLength = 4
        temp.CookieContainer = cookies
        temp.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1"
        'temp.ContentType = "application/x-www-form-urlencoded"
        temp.ContentLength = encodedPostData.Length
        temp.Method = "POST"
     
        Dim post As Stream
        post = temp.GetRequestStream
        post.Write(encodedPostData, 0, encodedPostData.Length)
        'post.Close()
        Try
            response = temp.GetResponse
        Catch ex As Exception

        End Try

        reader = New StreamReader(response.GetResponseStream, System.Text.ASCIIEncoding.ASCII)
        html = reader.ReadToEnd
and all variable like event_arg ,viewsource1,2,3 etc have proper data.
 
Last edited:
Back
Top