POST data is "lost" somewhere

UPDATE

So it turns out that internet exploder stranglehold on "security" to "marry" for being so badly secure was causing my problems. I had to check it out first haha. Thanks everyone for the input, he gave me ideas on how to optimize my application: D


I am writing a web application (in ASP.NET 3.5) that integrates with a platform application. The platform application takes the user's credentials and puts them in a "blank" HTML page consisting of a form with hidden elements containing the specified credentials and POSTS in webapp ( default.aspx

):

<HTML>
<HEAD>
<SCRIPT LANGUAGE=JSCRIPT>
    function OnLoad(){
        try {
            document.form1.submit();
        }
        catch(e){
        }
    }
</SCRIPT>
</HEAD>
<BODY OnLoad="OnLoad()">
    <FORM ACTION="http://localhost:51816/gs_ontheweb/default.aspx" METHOD=POST NAME=form1 TARGET="_NEW">
    <INPUT TYPE="HIDDEN" NAME="ClientID" VALUE="123456">
    <INPUT TYPE="HIDDEN" NAME="Password" VALUE="2830088828">
    <INPUT TYPE="HIDDEN" NAME="PracType" VALUE="051">
    <INPUT TYPE="HIDDEN" NAME="Encrypt" VALUE="12345620081111">
</FORM>
</BODY>
</HTML>

      

When my page loads, it calls the following function: default.aspx

Dim ClientID As String = Request.Form("ClientID")
Dim PassWord As String = Request.Form("Password")
Dim PracType As String = Request.Form("PracType")

      

Each of these results in blank lines. Any ideas on why this is happening? Thanks in advance.

EDIT: Is there something I need to tweak in my file to make this work correctly? Request.Params (" ") doesn't work. web.config

<param name>

0


source to share


3 answers


Your problem is the "Target" property on the form. Why is it here?

(I also bothered a bit to clean up my HTML)

<html>
    <head>
    <title>Test JS Post</title>
    <script type="text/javascript" language="javascript">
    <!--
        function OnLoad(){
            try
            {
                alert("Posting...");
                document.form1.submit();
            }
            catch(e)
            {
                alert("ERROR!");
                alert(e);
            }
        }
    //-->
    </script>
</head>
<body onload="OnLoad()">

    <form action="http://localhost:49684/Default.aspx" method="post" name="form1">

        <input type="hidden" name="ClientID" value="123456" />
        <input type="hidden" name="Password" value="2830088828" />
        <input type="hidden" name="PracType" value="051" />
        <input type="hidden" name="Encrypt" value="12345620081111" />

        <h1>This is in the form.  Submit me here:</h1><input type="submit" value="foo" />

    </form>

</body>
</html>

      



In the code behind Default.aspx

:

Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

    For Each value As String In Request.Form.Keys
        Debug.WriteLine(String.Format("{0} = ""{1}""", value, Request.Form.Item(value)))
    Next

End Sub

      

+3


source


Is this HTML only on the user's hard drive? It is possible browser security will not allow this POST as it is considered a risk.



As a test - take this exact HTML file and put it on your web server and then navigate to it. If it works, there might be a browser refusing to send data. You can check with Fiddler (for IE) or Firebug in FireFox.

0


source


Why not use System.Net.WebClient?

Sample code (sorry, this is C #. Sounds like you are looking for VB. I can't translate quickly.)

System.Net.WebClient wc = new System.Net.WebClient();
byte[] b;
byte[] res;
string formdata = "text=test text&password=secret&checkbox=on&textarea=a longer text sentence&submit=submit";

//    encode the form data string into a byte array 
b = System.Text.Encoding.ASCII.GetBytes(formdata);

// set the content type for a form 
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

// POST and get data
res = wc.UploadData("http://localhost:51816/gs_ontheweb/default.aspx", b);

//convert the return page from byte[] to ascii
string s = System.Text.Encoding.ASCII.GetString(res);

      

0


source







All Articles