473,394 Members | 1,709 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,394 software developers and data experts.

calling multiple web pages

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!
Nov 18 '05 #1
5 1484
Hi Mark,

Thank you for posting to the MSDN newsgroups.

I am interested in this issue and researching on it now. I will update you
as soon as possible.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #2
Hi Mark,

I have done a lot of research regarding this issue. Unfortunately, I have
not found any hints now. Is it possible for you to write a simple testing
project only for this issue and tell me how to reproduce the problem on my
side step by step? I certainly appreciate your time.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #3
Jacob,

Thank you for looking into this. I figured out how
to have the code call two pages instead of one, but maybe
you could help me figure out a secondary issue. The
following code calls the same page-www.solelsoftware.com--
twice in a row (although it could call two different
pages):

<%@ 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.solelsoftware.com/");
System.Net.HttpWebResponse HttpWResp =
(System.Net.HttpWebResponse)HttpWReq.GetResponse() ;

System.Net.HttpWebRequest HttpWReq2 =
(System.Net.HttpWebRequest) System.Net.WebRequest.Create
("http://www.solelsoftware.com/");
System.Net.HttpWebResponse HttpWResp2 =
(System.Net.HttpWebResponse)HttpWReq2.GetResponse( );

// 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>

In the above code HttpWResp contains the response from
the first call and HttpWResp2 contains the response from
the second call. The code then goes on to read the
response from HttpWResp into a stream "receiveStream" and
write it out to the browser. How would I write the
responses from both HttpWResp and HttpWResp2 to the
browser? Would I append HttpWResp2 onto "receiveStream"
before outputting to the browser? Ideally I would like
to be able to insert some Response.Write statements in
between outputting HttpWResp and HttpWResp2, so that I
could put a divider/explanation before HttpWResp2's
output. Thank you for your help!
-----Original Message-----
Hi Mark,

I have done a lot of research regarding this issue. Unfortunately, I have not found any hints now. Is it possible for you to write a simple testing project only for this issue and tell me how to reproduce the problem on my side step by step? I certainly appreciate your time.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.

Nov 18 '05 #4
Hi Mark,

I apologize for it if there is any misunderstanding.

As I understand, what you really want to know is how to get the stream from
both HttpWResp and HttpWResp2. Please refer to the following C# console
sample carefully.
--------------------------------------------
using System;
using System.Net;
using System.IO;
using System.Text;

namespace TestRequest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
// Creates an HttpWebRequest with the specified URL.
HttpWebRequest myHttpWebRequest =
(HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse myHttpWebResponse =
(HttpWebResponse)myHttpWebRequest.GetResponse();
// Gets the stream associated with the response.
Stream receiveStream = myHttpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
// Pipes the stream to a higher level stream reader with the required
encoding format.
StreamReader readStream = new StreamReader( receiveStream, encode );
Console.WriteLine("\r\nResponse stream received.");
Char[] read = new Char[256];
// Reads 256 characters at a time.
int count = readStream.Read( read, 0, 256 );
Console.WriteLine("HTML...\r\n");
while (count > 0)
{
// Dumps the 256 characters on a string and displays the string to the
console.
String str = new String(read, 0, count);
Console.Write(str);
count = readStream.Read(read, 0, 256);
}
Console.WriteLine("");
// Releases the resources of the response.
myHttpWebResponse.Close();
// Releases the resources of the Stream.
readStream.Close();
HttpWebRequest myHttpWebRequest2 =
(HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse myHttpWebResponse2 =
(HttpWebResponse)myHttpWebRequest2.GetResponse();
// Gets the stream associated with the response.
Stream receiveStream2 = myHttpWebResponse2.GetResponseStream();
Encoding encode2 = System.Text.Encoding.GetEncoding("utf-8");
// Pipes the stream to a higher level stream reader with the required
encoding format.
StreamReader readStream2 = new StreamReader( receiveStream2, encode2 );
Console.WriteLine("\r\nResponse stream received.");
Char[] read2 = new Char[256];
// Reads 256 characters at a time.
int count2 = readStream2.Read( read2, 0, 256 );
Console.WriteLine("HTML...\r\n");
while (count2 > 0)
{
// Dumps the 256 characters on a string and displays the string to the
console.
String str = new String(read2, 0, count2);
Console.Write(str);
count2 = readStream2.Read(read2, 0, 256);
}
Console.WriteLine("");
// Releases the resources of the response.
myHttpWebResponse2.Close();
// Releases the resources of the Stream.
readStream2.Close();
}
}
}
--------------------------------------------

For the question of how to write the stream to the browser, I am not sure
about your exact meaning. Based on the above sample, what we get from the
stream is a HTML file that can be displayed/opened in IE. If you want to
write it to the browser, you need to parse the content of the stream
yourself to make it can be write to the browser.

I hope it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #5
Jacob,

Thank you for your response. This is what I was
looking for. I am sorry for not being clearer earlier.
Thanks again.

-----Original Message-----
Hi Mark,

I apologize for it if there is any misunderstanding.

As I understand, what you really want to know is how to get the stream from both HttpWResp and HttpWResp2. Please refer to the following C# console sample carefully.
--------------------------------------------
using System;
using System.Net;
using System.IO;
using System.Text;

namespace TestRequest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application. /// </summary>
[STAThread]
static void Main(string[] args)
{
// Creates an HttpWebRequest with the specified URL. HttpWebRequest myHttpWebRequest =
(HttpWebRequest)WebRequest.Create ("http://www.microsoft.com"); // Sends the HttpWebRequest and waits for the response. HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse() ;
// Gets the stream associated with the response. Stream receiveStream = myHttpWebResponse.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); // Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader( receiveStream, encode ); Console.WriteLine("\r\nResponse stream received."); Char[] read = new Char[256];
// Reads 256 characters at a time. int count = readStream.Read( read, 0, 256 ); Console.WriteLine("HTML...\r\n");
while (count > 0)
{
// Dumps the 256 characters on a string and displays the string to the console.
String str = new String (read, 0, count); Console.Write(str);
count = readStream.Read (read, 0, 256); }
Console.WriteLine("");
// Releases the resources of the response. myHttpWebResponse.Close();
// Releases the resources of the Stream. readStream.Close();
HttpWebRequest myHttpWebRequest2 = (HttpWebRequest)WebRequest.Create ("http://www.microsoft.com"); // Sends the HttpWebRequest and waits for the response. HttpWebResponse myHttpWebResponse2 = (HttpWebResponse)myHttpWebRequest2.GetResponse( );
// Gets the stream associated with the response. Stream receiveStream2 = myHttpWebResponse2.GetResponseStream(); Encoding encode2 = System.Text.Encoding.GetEncoding("utf-8"); // Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream2 = new StreamReader( receiveStream2, encode2 ); Console.WriteLine("\r\nResponse stream received."); Char[] read2 = new Char[256];
// Reads 256 characters at a time. int count2 = readStream2.Read( read2, 0, 256 ); Console.WriteLine("HTML...\r\n");
while (count2 > 0)
{
// Dumps the 256 characters on a string and displays the string to the console.
String str = new String (read2, 0, count2); Console.Write(str);
count2 = readStream2.Read (read2, 0, 256); }
Console.WriteLine("");
// Releases the resources of the response. myHttpWebResponse2.Close();
// Releases the resources of the Stream. readStream2.Close();
}
}
}
--------------------------------------------

For the question of how to write the stream to the browser, I am not sure about your exact meaning. Based on the above sample, what we get from the stream is a HTML file that can be displayed/opened in IE. If you want to write it to the browser, you need to parse the content of the stream yourself to make it can be write to the browser.

I hope it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.

Nov 18 '05 #6

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

Similar topics

11
by: Ohaya | last post by:
Hi, I'm trying to understand a situation where ASP seems to be "blocking" of "queuing" requests. This is on a Win2K Advanced Server, with IIS5. I've seen some posts (e.g.,...
0
by: Mike Collins | last post by:
I apologize for using this newsgroup for what seems like a VB6 question, but I did not see a newsgroup for VB6. I also think I may not have the C# code setup correctly for calling from VB6. If...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
3
by: Shikari Shambu | last post by:
Hi All, I have a situation where multiple applications are sharing some pages/ controls. So, I have a separate common project that has the common pages/ controls. My question is how do I...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
2
by: Raul Medina | last post by:
I am trying to print the same visual basic report multiple times in my VB 6.0 application using the command <reportObject>.printReport False, rptRangeAllPages. The only thing that differs between...
3
by: Bart Van der Donck | last post by:
Hello, I'm having a hard time trying to configure printed output that consists of multiple pages. The idea is the following: <div style=" border: 1px solid blue; position: absolute; top:...
6
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public...
47
by: mukeshrasm | last post by:
Hi I am calling two pages using Ajax Get_Pages.php and Get_Content.php from combo box. Both pages are displayed based on selection from combo box. Main problem is that it is not showing the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.