473,804 Members | 4,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling multiple web pages

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!
Nov 18 '05 #1
5 1503
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.solelsoftwa re.com--
twice in a row (although it could call two different
pages):

<%@ 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.solelsoftwa re.com/");
System.Net.Http WebResponse HttpWResp =
(System.Net.Htt pWebResponse)Ht tpWReq.GetRespo nse();

System.Net.Http WebRequest HttpWReq2 =
(System.Net.Htt pWebRequest) System.Net.WebR equest.Create
("http://www.solelsoftwa re.com/");
System.Net.Http WebResponse HttpWResp2 =
(System.Net.Htt pWebResponse)Ht tpWReq2.GetResp onse();

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

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 "receiveStr eam" 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 "receiveStr eam"
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 misunderstandin g.

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 myHttpWebReques t =
(HttpWebRequest )WebRequest.Cre ate("http://www.microsoft.c om");
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse myHttpWebRespon se =
(HttpWebRespons e)myHttpWebRequ est.GetResponse ();
// Gets the stream associated with the response.
Stream receiveStream = myHttpWebRespon se.GetResponseS tream();
Encoding encode = System.Text.Enc oding.GetEncodi ng("utf-8");
// Pipes the stream to a higher level stream reader with the required
encoding format.
StreamReader readStream = new StreamReader( receiveStream, encode );
Console.WriteLi ne("\r\nRespons e stream received.");
Char[] read = new Char[256];
// Reads 256 characters at a time.
int count = readStream.Read ( read, 0, 256 );
Console.WriteLi ne("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(s tr);
count = readStream.Read (read, 0, 256);
}
Console.WriteLi ne("");
// Releases the resources of the response.
myHttpWebRespon se.Close();
// Releases the resources of the Stream.
readStream.Clos e();
HttpWebRequest myHttpWebReques t2 =
(HttpWebRequest )WebRequest.Cre ate("http://www.microsoft.c om");
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse myHttpWebRespon se2 =
(HttpWebRespons e)myHttpWebRequ est2.GetRespons e();
// Gets the stream associated with the response.
Stream receiveStream2 = myHttpWebRespon se2.GetResponse Stream();
Encoding encode2 = System.Text.Enc oding.GetEncodi ng("utf-8");
// Pipes the stream to a higher level stream reader with the required
encoding format.
StreamReader readStream2 = new StreamReader( receiveStream2, encode2 );
Console.WriteLi ne("\r\nRespons e stream received.");
Char[] read2 = new Char[256];
// Reads 256 characters at a time.
int count2 = readStream2.Rea d( read2, 0, 256 );
Console.WriteLi ne("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(s tr);
count2 = readStream2.Rea d(read2, 0, 256);
}
Console.WriteLi ne("");
// Releases the resources of the response.
myHttpWebRespon se2.Close();
// Releases the resources of the Stream.
readStream2.Clo se();
}
}
}
--------------------------------------------

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 misunderstandin g.

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 myHttpWebReques t =
(HttpWebReques t)WebRequest.Cr eate ("http://www.microsoft.c om"); // Sends the HttpWebRequest and waits for the response. HttpWebResponse myHttpWebRespon se = (HttpWebRespon se)myHttpWebReq uest.GetRespons e();
// Gets the stream associated with the response. Stream receiveStream = myHttpWebRespon se.GetResponseS tream(); Encoding encode = System.Text.Enc oding.GetEncodi ng("utf-8"); // Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader( receiveStream, encode ); Console.WriteLi ne("\r\nRespons e stream received."); Char[] read = new Char[256];
// Reads 256 characters at a time. int count = readStream.Read ( read, 0, 256 ); Console.WriteLi ne("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(s tr);
count = readStream.Read (read, 0, 256); }
Console.WriteLi ne("");
// Releases the resources of the response. myHttpWebRespon se.Close();
// Releases the resources of the Stream. readStream.Clos e();
HttpWebRequest myHttpWebReques t2 = (HttpWebReques t)WebRequest.Cr eate ("http://www.microsoft.c om"); // Sends the HttpWebRequest and waits for the response. HttpWebResponse myHttpWebRespon se2 = (HttpWebRespon se)myHttpWebReq uest2.GetRespon se();
// Gets the stream associated with the response. Stream receiveStream2 = myHttpWebRespon se2.GetResponse Stream(); Encoding encode2 = System.Text.Enc oding.GetEncodi ng("utf-8"); // Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream2 = new StreamReader( receiveStream2, encode2 ); Console.WriteLi ne("\r\nRespons e stream received."); Char[] read2 = new Char[256];
// Reads 256 characters at a time. int count2 = readStream2.Rea d( read2, 0, 256 ); Console.WriteLi ne("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(s tr);
count2 = readStream2.Rea d (read2, 0, 256); }
Console.WriteLi ne("");
// Releases the resources of the response. myHttpWebRespon se2.Close();
// Releases the resources of the Stream. readStream2.Clo se();
}
}
}
--------------------------------------------

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
4979
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., http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=Tidy7IDbDHA.2108%40cpmsftngxa06.phx.gbl) that indicate that ASP will queue up requests when they come in with the same "session".
0
2582
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 anyone can please help, I would greatly appreciate it. I have a C# DLL, code below that I am trying to call from a VB6 program. I read an article that said to run RegAsm.exe from the .Net SDK and this would enable you to reference the C# DLL from...
5
3446
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 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
3
2793
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 reference these pages/ controls from my ASP.NET web projects WEbApp1 url http://localhost/app1 C:\Apps\App1
9
2780
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 wizards. But, I have found that trying to do something "outside the norm" adds a rather large level of complexity and/or data replication. Background I have been commissioned to create a web-based application for a client. It has a formsaunthentication...
2
1889
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 each report is a label that get modified. The result is only the last report processed is printed with the other reports producing blank pages. If I put a delay so that each printReport command is called only after the preceding report is...
3
2798
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: 20px; left: 20px;
6
3992
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 string UID; public string PWD; }
47
3300
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 editor which is called on the Get_Content.php. in Main Page. I have included the js files in the head section. all the files are on the same directory.
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10577
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10320
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.