473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

doing a POST to .ASP from ASP.NET page

Hello,
What is the best way to do a POST from an ASP.NET page to
an old time ASP page. The ASP accesses the data through
Request.Form("username") method. Looks like a normal
WebRequest with POST method is not able to see the input
fields in the form of the posting ASP.NET page. I would
like to post something to the ASP page and get the
response back to the ASP.NET. Request.QueryString() is
working fine, only accessing the form contents have the
problem.

Thanks for any help

Regards,
John
Nov 15 '05 #1
6 10311
John,

How are you setting the values for the post when you are making the call
through an HttpWebRequest?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Edwards" <an*******@discussions.microsoft.com> wrote in message
news:00****************************@phx.gbl...
Hello,
What is the best way to do a POST from an ASP.NET page to
an old time ASP page. The ASP accesses the data through
Request.Form("username") method. Looks like a normal
WebRequest with POST method is not able to see the input
fields in the form of the posting ASP.NET page. I would
like to post something to the ASP page and get the
response back to the ASP.NET. Request.QueryString() is
working fine, only accessing the form contents have the
problem.

Thanks for any help

Regards,
John

Nov 15 '05 #2
Thanks for the reply. My ASP page looks something like the following

//myprocessor.asp
<%@ LANGUAGE="VBScript" %>

<%
strMemberGroup=Request.Form("MemberGroup")
s1 = "strMemberGroup=" & strMemberGroup & "<BR>"
Response.Write(s1)
Response.Write("done")
%>

Now my ASPX page goes something like the following. As you can see, there is
an input field MemberGroup in ASPX. And ASP is not able to get the value of
the input filed.

<form id="FormDomainMembers" name="FormDomainMembers" method="post"
runat="server">
<TABLE id="Table1">
</TBODY>
<TR>
<TD><input id="MemberGroup" type="hidden" name="MemberGroup"
runat="server"></TD>
<TD</TD>
<TD>
<asp:linkbutton id="LinkButtonAddMembers" runat="server">
submit request
</asp:linkbutton>
</TD>
</TR>
</TBODY>
</TABLE>
</form>

private void LinkButtonAddMembers_Click(object sender, System.EventArgs e)
{
string sURL = "http://localhost/myweb/myprocessor.asp";
WebRequest request = WebRequest.Create (sURL);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
writeToURL (request, sURL);
string htmlContent = retrieveFromURL (request);
Response.Write (htmlContent );
}

void writeToURL (WebRequest request, string data)
{
byte [] bytes = null;
bytes = System.Text.Encoding.ASCII.GetBytes (data);
request.ContentLength = bytes.Length;
Stream outputStream = request.GetRequestStream ();
outputStream.Write (bytes, 0, bytes.Length);
outputStream.Close ();
}

String retrieveFromURL (WebRequest request)
{
WebResponse response = request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader (responseStream);
return reader.ReadToEnd ();
}

Nov 15 '05 #3


John Edwars wrote:
Thanks for the reply. My ASP page looks something like the following

//myprocessor.asp
<%@ LANGUAGE="VBScript" %>

<%
strMemberGroup=Request.Form("MemberGroup")
s1 = "strMemberGroup=" & strMemberGroup & "<BR>"
Response.Write(s1)
Response.Write("done")
%>

Now my ASPX page goes something like the following. As you can see, there is
an input field MemberGroup in ASPX. And ASP is not able to get the value of
the input filed.

<form id="FormDomainMembers" name="FormDomainMembers" method="post"
runat="server">
<TABLE id="Table1">
</TBODY>
<TR>
<TD><input id="MemberGroup" type="hidden" name="MemberGroup"
runat="server"></TD>
<TD</TD>
<TD>
<asp:linkbutton id="LinkButtonAddMembers" runat="server">
submit request
</asp:linkbutton>
</TD>
</TR>
</TBODY>
</TABLE>
</form>

private void LinkButtonAddMembers_Click(object sender, System.EventArgs e)
{
string sURL = "http://localhost/myweb/myprocessor.asp";
WebRequest request = WebRequest.Create (sURL);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
writeToURL (request, sURL);
string htmlContent = retrieveFromURL (request);
Response.Write (htmlContent );
}

void writeToURL (WebRequest request, string data)
So for data you pass in sURL which is
"http://localhost/myweb/myprocessor.asp". {
byte [] bytes = null;
bytes = System.Text.Encoding.ASCII.GetBytes (data);
request.ContentLength = bytes.Length;
Stream outputStream = request.GetRequestStream ();


Then you send that URL as the request body. That doesn't help, you need
to send the form data (Request.Form) in the request body and not the URL.
I would guess if you just read the ASP.NET Request.InputStream and write
it to WebRequest request.GetRequestStream() then it will work fine. But
I haven't tested that.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 15 '05 #4


Martin Honnen wrote:


John Edwars wrote:
Thanks for the reply. My ASP page looks something like the following

//myprocessor.asp
<%@ LANGUAGE="VBScript" %>

<%
strMemberGroup=Request.Form("MemberGroup")
s1 = "strMemberGroup=" & strMemberGroup & "<BR>"
Response.Write(s1)
Response.Write("done")
%>

Now my ASPX page goes something like the following. As you can see,
there is
an input field MemberGroup in ASPX. And ASP is not able to get the
value of
the input filed.

<form id="FormDomainMembers" name="FormDomainMembers" method="post"
runat="server">
<TABLE id="Table1">
</TBODY>
<TR>
<TD><input id="MemberGroup" type="hidden" name="MemberGroup"
runat="server"></TD>
<TD</TD>
<TD>
<asp:linkbutton id="LinkButtonAddMembers" runat="server">
submit request
</asp:linkbutton>
</TD>
</TR>
</TBODY>
</TABLE>
</form>

private void LinkButtonAddMembers_Click(object sender,
System.EventArgs e)
{
string sURL = "http://localhost/myweb/myprocessor.asp";
WebRequest request = WebRequest.Create (sURL);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
writeToURL (request, sURL);
string htmlContent = retrieveFromURL (request);
Response.Write (htmlContent );
}

void writeToURL (WebRequest request, string data)

So for data you pass in sURL which is
"http://localhost/myweb/myprocessor.asp".
{
byte [] bytes = null;
bytes = System.Text.Encoding.ASCII.GetBytes (data);
request.ContentLength = bytes.Length;
Stream outputStream = request.GetRequestStream ();

Then you send that URL as the request body. That doesn't help, you need
to send the form data (Request.Form) in the request body and not the URL.
I would guess if you just read the ASP.NET Request.InputStream and write
it to WebRequest request.GetRequestStream() then it will work fine. But
I haven't tested that.


I wrote a quick test as follows

string SendPostData () {
string URL = @"http://localhost/javascript/test20040109.asp";
HttpWebRequest httpRequest = (HttpWebRequest) WebRequest.Create(URL);
httpRequest.Method = "POST";
httpRequest.ContentLength = Request.ContentLength;
httpRequest.ContentType = Request.ContentType;
Stream httpRequestStream = httpRequest.GetRequestStream();
byte[] b = new byte[512];
int readBytes;
while ((readBytes = Request.InputStream.Read(b, 0, b.Length)) != 0) {
httpRequestStream.Write(b, 0, readBytes);
}
httpRequestStream.Close();
StreamReader streamReader = new
StreamReader(httpRequest.GetResponse().GetResponse Stream());
string response = streamReader.ReadToEnd();
streamReader.Close();
return response;
}

and that works for me.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 15 '05 #5
Thanks Martin, that just does the job! Can I trouble you with one more
related issue?

The input box is a server type control, and I want to update the content of
the input box right before calling the SendPostData function you provided.
In this case, the ASP page gets the updated value from the input box only
during the second call. As you can see, the the first time ASP is called, it
gets the default value specified for the input box at design time. How can I
take care of that?

Regards,
John

Nov 15 '05 #6


John Edwars wrote:
The input box is a server type control, and I want to update the content of
the input box right before calling the SendPostData function you provided.
In this case, the ASP page gets the updated value from the input box only
during the second call. As you can see, the the first time ASP is called, it
gets the default value specified for the input box at design time. How can I
take care of that?


I am not sure I understand what you are doing. The first time your
ASP.NET page is called is probably with a HTTP GET request in which case
no data is POSTed at all and then it doesn't make sense to try to write
any request body to an ASP page.
In general that SendPostData function writes the exact request body the
ASP.NET page received to the ASP page thus if you want to receive data
with ASP.NET page but then change some values before you pass the data
on to the ASP page then the function doesn't help, you would better read
out values from Request.Form and build your own new request body for ASP.
But I am guessing, it is probably better if you post the relevant
snippets from your code. And you might want to use the
dotnet.framework.aspnet for ASP.NET questions.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: sketch | last post by:
I have one page that does 3 different things depending on $_GET: 1. It shows an index with items. 2. It shows an item with a form to submit an amount. 3. It confirms the amount. I was just...
17
by: Paul | last post by:
HI! I get an error with this code. <SCRIPT language="JavaScript"> If (ifp==""){ ifp="default.htm"} //--></SCRIPT> Basicly I want my iframe to have a default page if the user enters in...
4
by: John Edwars | last post by:
Thanks to Martin Honnen, I could successfully send the form data from an APS.NET page to ASP page. Now the issue is that the form in the ASP.NET page has input boxes, which I want to update...
27
by: Greg Smith | last post by:
Hello, I have been given a programming task that falls into the "impossible" category with my current skill set. I am hoping somebody out there knows how to do this and can save my b-t. I...
5
by: Scott Lyon | last post by:
I am having a strange problem. The program is a bit complex, but I'll try to simplify what I can. I apologize if this is complicated, but I think this would still be simpler than posting a bunch of...
4
by: Martin | last post by:
I know this might seem like an odd question. I've got a page that has a few url parameters. There's a couple of modes the page can be entered in, with correspondingly different urls params. ...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
5
by: Joey | last post by:
I am attempting to hook the onChange event for a dropdown list with javascript so that I can do some stuff and then initiate a postback with my code. I have not yet learned about how to do...
8
by: =?Utf-8?B?Tmlja28u?= | last post by:
Hi, I'm at my wits-end here. I'm a beginner with ASP/C# (using .NET 2003) and I'm trying to post variables from a classic ASP form to a ASP.NET form. The Classic ASP form was scripted with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.