Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI All
This is my code snippet

C#
var request = (HttpWebRequest)WebRequest.Create("http://xx.xx.xx.xx/xx/xx/xxx/xxx.aspx");
           var data1 = Encoding.ASCII.GetBytes(Url);
           request.Method = "POST";
           request.ContentType = "application/x-www-form-urlencoded";
           request.ContentLength = data1.Length;

           using (var stream = request.GetRequestStream())
           {
               stream.Write(data1, 0, data1.Length);
           }
           var response = (HttpWebResponse)request.GetResponse();
           var responseString =
                    new StreamReader(response.GetResponseStream()).ReadToEnd();


and am getting response string successfully
which is HTML form

HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Raligare Health </title>
    <script language="javascript" type="text/javascript">
        function submitForm() {
            var elm = document.forms[0].elements[0];
            elm.parentNode.removeChild(elm);
            document.forms[0].method = "post";
            document.forms[0].action = "https://xxx.xxx.com/xxx/xxx.run";
            document.forms[0].submit();
        }	   
    </script>
</head>
<body onload="submitForm();">
    <form method="post" action="xxx.aspx" id="form2">
    <div class="aspNetHidden">
        <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTM1MzQyOTg2M2Rk" />
    </div>
    <div class="aspNetHidden">
        <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWDQKV8tWeBQKUwbXvDALZyp+SAgLBkpHwAwLd44Q6Atf/o+4DArCBl4kJAoDqn+8IAoaV9JsNAtnX/9QNArSO36MFAo3+jNEEAqiXqasB" />
    </div>
    <div>
        <input type="hidden" name="agentId" id="agentId" value="20008025" />
        <input type="hidden" name="quotationReferenceNum" id="quotationReferenceNum" value="0" />
        <input type="hidden" name="emailAddress" id="emailAddress" value="raj@yahoo.in" />
        <input type="hidden" name="mobileNum" id="mobileNum" value="9873598972" />
        <input type="hidden" name="productFamily" id="productFamily" value="HEALTH" />
        <input type="hidden" name="pCode" id="pCode" value="10001101" />
        <input type="hidden" name="sumInsured" id="sumInsured" value="005" />
        <input type="hidden" name="coverType" id="coverType" value="INDIVIDUAL" />
        <input type="hidden" name="numberOfAdult" id="numberOfAdult" value="0" />
        <input type="hidden" name="numberOfChildren" id="numberOfChildren" value="0" />
        <input type="hidden" name="ageGroupOfEldestMember" id="ageGroupOfEldestMember" value="25 - 35" />
        <input type="hidden" name="tenure" id="tenure" value="1" />
    </div>
    </form>
</body>
</html>


Now i have to submit this form and this form should redirect me to another page.How to do it..?
can anybody help me..
Posted
Updated 3-Jun-14 0:06am
v3

1 solution

I assume you're trying to do all of this with code and not a browser?

You have to load the HTML into an XMLReader.

Read through the XML to find the form element and all the input elements.

Get the action attribute of the form element as this is the address to which you should post the form back to.

Get the value and name attributes from each of the input elements.

Then use the action and name, value pairs to build up a new WebRequest object.

Then submit the web request.
 
Share this answer
 
Comments
_Starbug_ 16-Feb-19 8:22am    
@Stephen Hewison: can you please help me with this form http://www.shenel.ml

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900