Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

POST to page using asp.net

16 views
Skip to first unread message

csgraham74

unread,
Oct 4, 2007, 12:11:29 PM10/4/07
to
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

unread,
Oct 4, 2007, 12:30:20 PM10/4/07
to
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)

sloan

unread,
Oct 4, 2007, 1:27:43 PM10/4/07
to


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();
}

"csgraham74" <csgra...@gmail.com> wrote in message
news:1191514289.8...@n39g2000hsh.googlegroups.com...

0 new messages