If you need to post data to some other website or URL via post method then this article is the perfect solution.
This article references to the article provided in
C sharp corner thanks to Jigar Desai
I just followed the article and did it in vb. You can click on above link to get the c# code.
As per the above article
Possible Solutions
- One possible solution to this problem is to Create your own form control and use it on page this will allow you to change action of form, but again what if you do not want some existing input elements in current page to go to post.
- There is good way to post form data using HttpWebResponse & HttpWebRequest class if you want to post data behind the scenes, but if you want to post data using user browser then you are stuck
We have solved this by following way:
Create a RemotePost class (responsible for doing the job) as below:
Public Class RemotePost
Private Inputs As System.Collections.Specialized.NameValueCollection = _
New System.Collections.Specialized.NameValueCollection
Public URL As String = ""
Public Method As String = "post"
Public FormName As String = "form1"
Public Sub Add(ByVal name As String, ByVal value As String)
Inputs.Add(name, value)
End Sub
Public Sub Post()
Dim i As Int16
'System.Web.HttpContext.Current.Response.Clear()
'System.Web.HttpContext.Current.Response.Write("")
'System.Web.HttpContext.Current.Response.Write(String.Format("", FormName))
'System.Web.HttpContext.Current.Response.Write(String.Format("", FormName, Method, URL))
System.Web.HttpContext.Current.Response.Clear()
System.Web.HttpContext.Current.Response.Write("")
System.Web.HttpContext.Current.Response.Write(String.Format(""))
System.Web.HttpContext.Current.Response.Write(String.Format("
Now The posting Page which has a linkbutton
asp:LinkButton id="lnkbtnSmartTickets" Runat="server" >test post< /asp:LinkButton
And the code looks like below:
Private Sub lnkbtnPostThis_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim myRemotePost As New RemotePost
myRemotePost.URL = "Receiver.aspx"
myRemotePost.Add("param1", "this is prateek 1")
myRemotePost.Add("param2", "this is regmi2")
myRemotePost.Post()
End Sub
Now Receiver.aspx will have following code on its form load
Dim myRemotePost As New RemotePost
myRemotePost.URL = "Receiver.aspx"
myRemotePost.Add("param1", "this is prateek 1")
myRemotePost.Add("param2", "this is regmi2")
myRemotePost.Post()
End Sub
Now Receiver.aspx will have following code on its form load
If Not Request.Form("param1") = Nothing Then
Response.Write("param1: " & Request.Form("param1"))
End If
If Not Request.Form("param2") = Nothing Then
Response.Write("param2: " & Request.Form("param2"))
End If
No comments:
Post a Comment