Post a html fields to a specific url?????????
-
Hi friends, Can anyone advice me how to post some html fields to a specific url (https) using .net and c#. Thanks and Rgds Nithin
-
Hi friends, Can anyone advice me how to post some html fields to a specific url (https) using .net and c#. Thanks and Rgds Nithin
You could firstly just sent the action of the form to the destination, which would be the easiest way. However, a while back I wrote a simple class which would allow you to post to a Url from code which is included below in case you find it useful
Public Class Poster #Region " Properties " Private values As New System.Collections.Specialized.NameValueCollection Private _postUrl As String Public Property PostUrl() As String Get Return _postUrl End Get Set(ByVal value As String) _postUrl = value End Set End Property Private _formName As String = "form1" Public Property FormName() As String Get Return _formName End Get Set(ByVal value As String) _formName = value End Set End Property Private _method As String = "POST" Public Property Method() As String Get Return _method End Get Set(ByVal value As String) _method = value End Set End Property Public Sub AddValue(ByVal name As String, ByVal value As String) values.Add(name, value) End Sub #End Region #Region " Publish Methods " Public Sub Post() If PostUrl Is Nothing Then Throw New Exception("No Url specified") If FormName Is Nothing Then Throw New Exception("No Form Name specified") If String.IsNullOrEmpty(Method) Then Throw New Exception("No method specified") 'if values.Count=0 then throw new Exception("No post values supplied") HttpContext.Current.Response.Clear() HttpContext.Current.Response.Write("") HttpContext.Current.Response.Write(String.Format("", FormName)) HttpContext.Current.Response.Write(String.Format(" ", FormName, Method, PostUrl)) For i As Integer = 0 To values.Count - 1 System.Web.HttpContext.Current.Response.Write(String.Format("", values.Keys(i), values(values.Keys(i)))) Next HttpContext.Current.Response.Write(" ") HttpContext.Current.Response.Write("") HttpContext.Current.Response.End() End Sub #End Region End Class