XMLHttp from Server

Discussion in 'ASP .Net' started by Dave H, May 5, 2005.

  1. Dave H

    Dave H Guest

    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
    Dave H, May 5, 2005
    #1
    1. Advertising

  2. There is a sample that is application to both the .NET Compact Framework
    and the .NET Framework.

    Search for "bool Upload" in this article

    http://www.eggheadcafe.com/articles/compactframeworkencryption.asp

    --
    2004 and 2005 Microsoft MVP C#
    Robbe Morris
    http://www.robbemorris.com
    http://www.masterado.net/home/listings.aspx



    "Dave H" <> wrote in message
    news:...
    >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
    >
    >
    >
    Robbe Morris [C# MVP], May 5, 2005
    #2
    1. Advertising

  3. 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.)
    Steven Cheng[MSFT], May 6, 2005
    #3
  4. Dave H

    Dave H Guest

    I've done it from client side JS code, I wanted the same type from ASP
    server side code.

    Thanks to you both... Dave

    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > 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.)
    >
    >
    >
    >
    >
    Dave H, May 6, 2005
    #4
  5. 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.)
    Steven Cheng[MSFT], May 6, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    3
    Views:
    538
  2. Raúl Martín
    Replies:
    1
    Views:
    10,775
    Natty Gur
    May 13, 2004
  3. CsaaGuy
    Replies:
    3
    Views:
    1,289
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jan 28, 2006
  4. yawnmoth

    Msxml*.XMLHTTP vs. Microsoft.XMLHTTP

    yawnmoth, Nov 7, 2006, in forum: Javascript
    Replies:
    11
    Views:
    374
    Matt Kruse
    Nov 9, 2006
  5. Replies:
    2
    Views:
    96
    Bjoern Hoehrmann
    Jul 30, 2008
Loading...

Share This Page