XMLHttp from Server

  • Thread starter Thread starter Dave H
  • Start date Start date
D

Dave H

I want to use XMLHTTP or something like it from my server code.

I'm trying to call a web page, and I want the results back into a string.

ideas? Thanks, Dave
 
Hi Dave,

As for calling a web page and get the response stream text, where will you
make this call ? In your ASP.NET web application 's serverside code( .net
managed code) or in clientside script code?

If the call is made in asp.net serverside code( c# or vb.net), I think we'd
better use the HttpWebRequest class in the .net 's BCL which has more
powerful functions on http network processing such as making http get/post
request and get the response stream, here is a tech article discussing on
this:

#How To: Fetching Web Pages with HTTP
http://www.csharp-station.com/HowTo/HttpWebFetch.aspx

If you're making the call in clientside script, you can consider using
XMLHttp, here are the MSDN reference on using IXMLHTTPRequest ( XMLHttp is
one of the implementation of that COM interface):

#IXMLHTTPRequest
http://msdn.microsoft.com/library/en-us/xmlsdk/html/xmobjXMLHttpRequest.asp?
frame=true

#Using Microsoft's XMLHTTP Object to Get Data From Other Web Pages
http://www.4guysfromrolla.com/webtech/110100-1.shtml

@@@Note: in clientside code, we use XMLHTTP, however, in serverside code
(such as classic asp page or other server app), we should use ServerXMLHTTP
instead:

#How To Submit Form Data by Using XMLHTTP or ServerXMLHTTP Object
http://support.microsoft.com/default.aspx?scid=kb;en-us;290591


BTW, All the MSXML component (COM based) are not supported to use in .net
managed code, we should always use the buildin .net fundamental class
library's components if possible.

#INFO: Use of MSXML is Not Supported in .NET Applications
http://support.microsoft.com/default.aspx?scid=kb;en-us;815112

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
I've done it from client side JS code, I wanted the same type from ASP
server side code.

Thanks to you both... Dave
 
Thanks for your prompt response Dave,

So since you are wanting to do it at serverside, we have the following
means:

1. Using ServerXMLHTTP component in classic ASP page , we can just
vbscript or jscript in asp page.

#Using ServerXMLHTTP Directly
http://msdn.microsoft.com/library/en-us/xmlsdk/html/xmobjxmldomserverxmlhttp
_using_directly.asp?frame=true

2. Using HttpWebRequest class in asp.net web page, we can use C# or VB.NET.

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemNetHttpWebRequ
estClassGetResponseTopic.asp?frame=true


For your convenience, I've pasted two test code snippet below. Hope helps.


ASP server code (JScript)
===========================
<%@ Language="JScript" %>

<%

var url = "http://www.asp.net";
var objSrvHTTP;
objSrvHTTP = Server.CreateObject ("Msxml2.ServerXMLHTTP.3.0");
objSrvHTTP.open ("GET",url, false);
objSrvHTTP.send ();

Response.Clear();
Response.ContentType = "text/html";
Response.Write (objSrvHTTP.responseText);
Response.End();

%>
============================


ASP.NET serverside code (C#)
============================
private void Page_Load(object sender, System.EventArgs e)
{
string url = "http://www.w3.org";

HttpWebRequest webreq = WebRequest.Create(url) as HttpWebRequest;

webreq.Method = "GET";

//specify proxy if necessary
//webreq.Proxy = new WebProxy("xxxx",80);

HttpWebResponse webrep = webreq.GetResponse() as HttpWebResponse;

StreamReader sr = new StreamReader(webrep.GetResponseStream());

string responseHtml = sr.ReadToEnd();

sr.Close();
webrep.Close();


Response.ClearContent();
Response.Write(responseHtml);
Response.End();
}


============================


Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Send xml from javascript and recive it from aspx page 1
little Ajax problem 3
XMLHTTP question 1
xmlhttp post question 3
ASP.NET suppress response HTML 3
AJAX - Query 1
XMLHTTP 4
XMLHTTP 2

Back
Top