Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

POST to page using asp.net

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
csgraham74 - 04 Oct 2007 17:11 GMT
Just a quick one - im trying to post values to a page using a method
below. im coding in asp.net vb. i was wondering how i also redirect to
the page as well as post the values at the same time. e.g. in html it
would be something like

<form action=https://www.text.cgi method=post>
<input type=visible name="val1" value="<%=val1%>">
<input type=visible name="val2" value="<%=val2%>">
<input type=submit value="Proceed to server" id="Submit1"
language="javascript" onclick="return Submit1_onclick()">
</form>

posting in asp.net - i think ??????  any help appreciated

   Public Shared Function readHtmlPage(ByVal postData As String) As
String
       Dim result As String = ""
       Dim strPost As String = postData
       Dim myWriter As StreamWriter

       Dim objRequest As HttpWebRequest = WebRequest.Create("https://
www.test.cgi")
       objRequest.Method = "POST"
       objRequest.ContentLength = strPost.Length
       objRequest.ContentType = "application/x-www-form-urlencoded"

       Try
           myWriter = New StreamWriter(objRequest.GetRequestStream())
           myWriter.Write(strPost)
       Catch e As Exception
           Return e.Message
       Finally
           myWriter.Close()
       End Try

       Dim objResponse As HttpWebResponse = objRequest.GetResponse()
       Dim sr As StreamReader
       sr = New StreamReader(objResponse.GetResponseStream())
       result = sr.ReadToEnd()
       sr.Close()

            Return result
   End Function
bruce barker - 04 Oct 2007 17:30 GMT
your postdata would be something like:

string.Format("val1={0}&val2={1}&Submit1=Proceed+to+server",
    HttpUtility.UrlEncode(val1),
    HttpUtility.UrlEncode(val1));
   
-- bruce (sqlwork.com)

> Just a quick one - im trying to post values to a page using a method
> below. im coding in asp.net vb. i was wondering how i also redirect to
[quoted text clipped - 39 lines]
>              Return result
>     End Function
sloan - 04 Oct 2007 18:27 GMT
I don't know if this helps or not.

But I dug up some old code:

FormPostCollection and FormPostItem is just a simple name/value pair.

As in.

EmpID=123
fpi.Key , fpi.Value

You could replace with NamedValuePairCollection or similar dictionary
object.

I just remember it taking several days to get all the nooks/crannies worked
out .

 private void postDataToHttpWebRequest ( HttpWebRequest webRequest ,
Collections.FormPostCollection  formPostCollec)
 {

  if (null != formPostCollec )
  {

   //byte[]  data =
MeasInc.AsynchronousFramework.SerializationLib.SerializationHelper.StringToUnicodeByteArray
(PARAMTER_DS_FORM_KEY +"="+parameterDS.GetXml());

   ASCIIEncoding encoding=new ASCIIEncoding();

   byte[] data = encoding.GetBytes(this.buildPostString(formPostCollec));

   webRequest.Method = "POST";
   webRequest.ContentType="application/x-www-form-urlencoded";
   //oHttpWebRequest.ContentType = "text/xml";//Does Not Work

   webRequest.ContentLength = data.Length;
   Stream newStream=webRequest.GetRequestStream();
   // Send the data.
   newStream.Write(data,0,data.Length);
   newStream.Close();
  }

 }

 private string buildPostString ( Collections.FormPostCollection
formPostCollec)
 {

  StringBuilder sb = new StringBuilder();

  foreach (BusinessObjects.FormPostItem fpi in formPostCollec)
  {
   //string postValue = Encode(Request.Form(postKey));
   sb.Append( string.Format("{0}={1}&", fpi.Key , fpi.Value ));
  }

  return sb.ToString();
 }

> Just a quick one - im trying to post values to a page using a method
> below. im coding in asp.net vb. i was wondering how i also redirect to
[quoted text clipped - 39 lines]
>             Return result
>    End Function

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.