Hello,
I have a page DoBatchWork.asp x 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.asp x is:
<%@ Page language="c#" EnableViewState ="false"
ContentType="te xt/html" %>
<script language="C#" runat="server">
void Page_Load(Objec t Src, EventArgs E ) {
System.Net.Http WebRequest HttpWReq =
(System.Net.Htt pWebRequest) System.Net.WebR equest.Create
("http://www.mysite.com/sites/site1/DoSomeWork.aspx ");
System.Net.Http WebResponse HttpWResp =
(System.Net.Htt pWebResponse)Ht tpWReq.GetRespo nse();
// Insert code that uses the response object.
// From "HttpWebRespons e.GetResponseSt ream
Method" in documentation
System.IO.Strea m receiveStream =
HttpWResp.GetRe sponseStream();
System.Text.Enc oding encode =
System.Text.Enc oding.GetEncodi ng("utf-8");
// Pipes the stream to a higher level stream reader
with the required encoding format.
System.IO.Strea mReader readStream = new
System.IO.Strea mReader( 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.Clos e();
}
</script>
I got this code from the
HttpWebResponse .GetResponseStr eam 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.asp x 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.Strea mReader readStream2 = new
System.IO.Strea mReader( 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!