POST method ?

  • Thread starter Thread starter WJ
  • Start date Start date
W

WJ

I have an Asp.Net page that redirects the user to another page with a piece
of data to be passed. Below is the c# instruction:

Response.Redirect("mySpecialPage.aspx?go1="+strGoName);

This will expose the "go1" parameter on the Address field of the MS/IE
browser because it uses the "GET" method. Is there a way that I can force
the system to use the "POST" method with the above payload ?

Thanks for your help,

John
 
POST a form to the URL. Response.Redirect() sends a header to the browser
instructing it to request that URL. That Request will always be GET. You
can't send a header to the browser instructing it to send a POST request.

You can add a non-WebForm (client-side) HTML form to the page anywhere
outside of the WebForm form. You can then use JavaScript to Post to its
ACTION property. A WebForm always has an ACTION property that is the same
URL as the page it's on. That's how ASP.Net does server-side event handling.
But you can certainly add another form to the page, set its ACTION property
to the URL you want to Post to, and submit it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Kevin Spencer said:
POST a form to the URL. Response.Redirect() sends a header to the browser

Thanks for your response. I understand all this and I know that GET method
also uses form too. I just wonder why not make one for POST also. It is very
convenient.

John
 
Thanks for your response. I understand all this and I know that GET method
also uses form too.

A Form can POST or GET, but Response.Redirect() is always GET. As for why,
you would have to ask the W3C.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Hi John,

You can simulate a post using the WebClient class. Here's the idea:

Sub DoPost()
Dim uriString As String = _
"http://localhost/p4320work/mySpecialPage.aspx"
Dim strGoName As String
strGoName = TextBox1.Text
' Create a new WebClient instance.
Dim myWebClient As New System.Net.WebClient
Dim myNameValueCollection As New _
System.Collections.Specialized.NameValueCollection
myNameValueCollection.Add("go1", strGoName)
myNameValueCollection.Add("Button1", "")
Dim responseArray As Byte() = myWebClient.UploadValues _
(uriString, "POST", myNameValueCollection)

Label1.Text = "Response received was :" & _
System.Text.Encoding.ASCII.GetString(responseArray)
End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Call DoPost()
End Sub

Ken
Microsoft MVP [ASP.NET]
 
Thanks Ken. That does it. However, it would be nice if the whole thing can
be condensed in one statement.

John
 
Glad to help.

I suppose I could spend some time on it. It might be a long statement!
<grin>
 
Ken Cox said:
I suppose I could spend some time on it. It might be a long statement!
<grin>

You done enough already. Let Bill Gate does it. All I need is a
Response.Redirect("mySpecialPage.aspx?go1="+strGoName,"POST");

:)

John
 
Dear Ken,
if i have an asp page with 2 input controls (username & password),i want
from my asp.net page to post these data and submit the form and see the
returned URL,if the user has been authenticated or not.

all sample i have seen is to pass the data on POST ,considering the page is
working by passing values as Quesry string.... if not ? this method is work
using HTTPWeb Request...... or there's another method to do the above
scenario.

i want a sample code to this.
what i did,simpy i went to the login page of that system,and take the
Control IDs for the username and password.....but pass it as content on POST
doesnt work.....

please clarify my ideas if there's sometinhg wrong.

Ken Cox said:
Hi John,

You can simulate a post using the WebClient class. Here's the idea:

Sub DoPost()
Dim uriString As String = _
"http://localhost/p4320work/mySpecialPage.aspx"
Dim strGoName As String
strGoName = TextBox1.Text
' Create a new WebClient instance.
Dim myWebClient As New System.Net.WebClient
Dim myNameValueCollection As New _
System.Collections.Specialized.NameValueCollection
myNameValueCollection.Add("go1", strGoName)
myNameValueCollection.Add("Button1", "")
Dim responseArray As Byte() = myWebClient.UploadValues _
(uriString, "POST", myNameValueCollection)

Label1.Text = "Response received was :" & _
System.Text.Encoding.ASCII.GetString(responseArray)
End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Call DoPost()
End Sub

Ken
Microsoft MVP [ASP.NET]

WJ said:
I have an Asp.Net page that redirects the user to another page with a piece
of data to be passed. Below is the c# instruction:

Response.Redirect("mySpecialPage.aspx?go1="+strGoName);

This will expose the "go1" parameter on the Address field of the MS/IE
browser because it uses the "GET" method. Is there a way that I can force
the system to use the "POST" method with the above payload ?

Thanks for your help,

John
 
Back
Top