M
Mark Fox
Hello,
I have a page DoBatchWork.aspx that my web host's
cron requests periodically. It currently calls another
web page that does some batch processing. The code I am
currently using in DoBatchWork.aspx is:
<%@ Page language="c#" EnableViewState="false"
ContentType="text/html" %>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E ) {
System.Net.HttpWebRequest HttpWReq =
(System.Net.HttpWebRequest) System.Net.WebRequest.Create
("http://www.mysite.com/sites/site1/DoSomeWork.aspx");
System.Net.HttpWebResponse HttpWResp =
(System.Net.HttpWebResponse)HttpWReq.GetResponse();
// Insert code that uses the response object.
// From "HttpWebResponse.GetResponseStream
Method" in documentation
System.IO.Stream receiveStream =
HttpWResp.GetResponseStream();
System.Text.Encoding encode =
System.Text.Encoding.GetEncoding("utf-8");
// Pipes the stream to a higher level stream reader
with the required encoding format.
System.IO.StreamReader readStream = new
System.IO.StreamReader( receiveStream, encode );
char[] read = new char[256];
// Reads 256 characters at a time.
int count = readStream.Read( read, 0, 256 );
while (count > 0)
{
// Dumps the 256 characters on a string
and displays the string to the console.
string str = new string(read, 0, count);
Response.Write(str);
count = readStream.Read(read, 0, 256);
}
// Releases the resources of the response.
HttpWResp.Close();
// Releases the resources of the Stream.
readStream.Close();
}
</script>
I got this code from the
HttpWebResponse.GetResponseStream method documentation.
It works great, but now I have a second page
DoMoreWork.aspx at a different URL
(http://www.mysite.com/site2/DoMoreWork.aspx) that I
would like DoBatchWork.aspx to also call in its page load
function. When I copied and pasted the code for calling
DoSomeWork.aspx (appending a "2" to all the variable
names), I get an error that asp.net is unable to read the
stream on line
System.IO.StreamReader readStream2 = new
System.IO.StreamReader( receiveStream2, encode2 );
I suspect this is because it seems the first page's
request closes the response object or something. My
question is this: How do I get it to call two pages?
Any help would appreciated. Thanks so much!
I have a page DoBatchWork.aspx that my web host's
cron requests periodically. It currently calls another
web page that does some batch processing. The code I am
currently using in DoBatchWork.aspx is:
<%@ Page language="c#" EnableViewState="false"
ContentType="text/html" %>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E ) {
System.Net.HttpWebRequest HttpWReq =
(System.Net.HttpWebRequest) System.Net.WebRequest.Create
("http://www.mysite.com/sites/site1/DoSomeWork.aspx");
System.Net.HttpWebResponse HttpWResp =
(System.Net.HttpWebResponse)HttpWReq.GetResponse();
// Insert code that uses the response object.
// From "HttpWebResponse.GetResponseStream
Method" in documentation
System.IO.Stream receiveStream =
HttpWResp.GetResponseStream();
System.Text.Encoding encode =
System.Text.Encoding.GetEncoding("utf-8");
// Pipes the stream to a higher level stream reader
with the required encoding format.
System.IO.StreamReader readStream = new
System.IO.StreamReader( receiveStream, encode );
char[] read = new char[256];
// Reads 256 characters at a time.
int count = readStream.Read( read, 0, 256 );
while (count > 0)
{
// Dumps the 256 characters on a string
and displays the string to the console.
string str = new string(read, 0, count);
Response.Write(str);
count = readStream.Read(read, 0, 256);
}
// Releases the resources of the response.
HttpWResp.Close();
// Releases the resources of the Stream.
readStream.Close();
}
</script>
I got this code from the
HttpWebResponse.GetResponseStream method documentation.
It works great, but now I have a second page
DoMoreWork.aspx at a different URL
(http://www.mysite.com/site2/DoMoreWork.aspx) that I
would like DoBatchWork.aspx to also call in its page load
function. When I copied and pasted the code for calling
DoSomeWork.aspx (appending a "2" to all the variable
names), I get an error that asp.net is unable to read the
stream on line
System.IO.StreamReader readStream2 = new
System.IO.StreamReader( receiveStream2, encode2 );
I suspect this is because it seems the first page's
request closes the response object or something. My
question is this: How do I get it to call two pages?
Any help would appreciated. Thanks so much!