Convert VB Script to C# script with MSXML2 request: Server.CreateObject("MSXML2.ServerXMLHTTP")

Posted on 2004-11-28
Last Modified: 2012-05-05
I know C#, but not VB.  
How do I create the equivalent C# script for this VB Syntax?

Set xml Server.CreateObject("MSXML2.ServerXMLHTTP")


complete function is here. but I can do the rest out, once I get the correct Objects set up.

Function GetContent(url)
    Dim xmlHttp
    Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
    xml.Open "GET", url, True
    Call xml.Send()

      If xml.readyState <> 4 Then
        xml.waitForResponse 3
    End If
     If Err.Number <> 0 Then
         If (xml.readyState <> 4) Or (xml.Status <> 200) Then
              strData = "Problem communicating with remote server..."
              strData = xml.ResponseText
         End If
    End If
    GetContent = strData
End Function


Question by:paygo
    LVL 46

    Accepted Solution

    I may be very wrong about this as I don't know much about .Net yet and even less about C#, but is this what you need?

    string postData = "";
    string uriString = "";
    string strXML ;

    XMLHTTPClass xmlHTTP = new XMLHTTPClass();"POST", uriString,false,null,null) ;
    xmlHTTP.send(postData) ;

    while(xmlHTTP.readyState != 4)
    strXML = (string)xmlHTTP.responseText;

    Author Comment

    Thanks fritz this is correct.

    But I get a MSXML4.dll  access denied error with some sites.

    This is another post question I believe
    LVL 46

    Expert Comment

    Thank you and best of luck. Don't forget, we have an ASP.Net area--you might have better luck finding your answer there.


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now