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/