.NETGURU
Sending data to other web-app
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.aspnet.

Post a new message to this list...

Christina N
What is the easiest way to make an ASP.Net application send data to another
web-app? For instance I would like APP3 to log user stats from APP1 and
APP2. The applications are located on different IIS servers.

Put in another way, can I send a datastring to another web-app without
having the IE client expecting a post back from that server?

Best regards,
Christina

Reply to this message...
 
    
Sayed Hashimi
Christina,

Here is a code snippet that shows how to use HttpWebRequest to call
your App3.

// From APP1 or APP2
-----------------------------------------------------------------------------------------------------
string strData = "data=call-from-app2";

HttpWebRequest httpWebRequest=httpWebRequest =
(HttpWebRequest)WebRequest.Create("App3URL");
// call with a POST
httpWebRequest.Method = "POST";

// POST name-value pairs
String contentType = "application/x-www-form-urlencoded";
httpWebRequest.ContentType = contentType;
// write to the request stream
byte[] data = new ASCIIEncoding().GetBytes(strData);
Stream reqStream = httpWebRequest.GetRequestStream();
reqStream.Write(data,0,data.Length);
reqStream.Close();
// execute the request synchronously
HttpWebResponse httpWebResponse =
(HttpWebResponse)httpWebRequest.GetResponse();
-----------------------------------------------------------------------------------------------------

The above will take care of you passing data to App3. Now, will you be
writing App 3 too, or does that
code already exist? If you will write App 3 yourself, then, you can
get to the request input stream and
process the input data that your wrote to the stream above. You can do
the following:

Stream inputStream = new StreamReader(Request.InputStream);

// You can get to the header, params, etcs of the request by doing the
following:

// ---------------HTTP HEADERS-----------------
int i=0;
for(i=0; i<Request.Headers.Keys.Count; i++)
{
    Console.WriteLine(Request.Headers.Keys[i]+"="+Request.Headers[Request.Headers.Keys[i]]);
}
// ---------------HTTP PARAMS-----------------
for(i=0; i<Request.Params.Keys.Count; i++)
{
    Console.WriteLine(Request.Params.Keys[i]+"="+Request.Params[Request.Params.Keys[i]]);
}
---------------SERVER VARIABLES------------
for(i=0; i<Request.ServerVariables.Keys.Count; i++)
{
    Console.WriteLine(Request.ServerVariables.Keys[i]+"="+Request.ServerVariables[Request.ServerVariables.Keys[i]]);
}

One final note about what you are doing. If you are logging request
info for every request, then I recommend that
you write an HttpModule to encapsulate that from the rest of the
application. Writing HttpModules to handle
this is the way to go. Give me some more information on what you want
to do and I will help you along a bit more.

sayed

"Christina N" <Click here to reveal e-mail address> wrote in message news:<Click here to reveal e-mail address>...
[Original message clipped]

Reply to this message...
 
    
Shiva
One option is to use HttpWebRequest to manually post the data to the logging
app.

"Christina N" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
What is the easiest way to make an ASP.Net application send data to another
web-app? For instance I would like APP3 to log user stats from APP1 and
APP2. The applications are located on different IIS servers.

Put in another way, can I send a datastring to another web-app without
having the IE client expecting a post back from that server?

Best regards,
Christina

Reply to this message...
 
    
Christina N
Okay, but HOW do I do that? Can you help me?

Christina

"Shiva" <Click here to reveal e-mail address> wrote in message
news:O%Click here to reveal e-mail address...
> One option is to use HttpWebRequest to manually post the data to the
logging
[Original message clipped]

Reply to this message...
 
    
Shiva
Hi,
Check these for a sample:
http://www.netomatix.com/HttpPostData.aspx
http://www.codeproject.com/csharp/HttpWebRequest_Response.asp

HTH.

"Christina N" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
Okay, but HOW do I do that? Can you help me?

Christina

"Shiva" <Click here to reveal e-mail address> wrote in message
news:O%Click here to reveal e-mail address...
> One option is to use HttpWebRequest to manually post the data to the
logging
[Original message clipped]

Reply to this message...
 
 
System.Console
System.IO.StreamReader
System.Net.HttpWebRequest
System.Net.HttpWebResponse
System.Net.WebRequest
System.Text.ASCIIEncoding




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification