Solved

need ASP -> C# translation help

Posted on 2004-08-30
3
327 Views
Last Modified: 2008-02-01
Hello,

I need to convert the following code into C#...

Dim objXmlHttp
Dim strHTML

Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")

objXmlHttp.open "GET","http://website1.com/test?Success=http://www.success.com&Failure=http://www.failure.com", False

objXmlHttp.send

strHTML = objXmlHttp.responseText

Set objXmlHttp = Nothing
0
Comment
Question by:garystark
3 Comments
 
LVL 9

Assisted Solution

by:s_sansanwal
s_sansanwal earned 250 total points
ID: 11938762
Simple way would be to use same COM in .net
In VS.NET, add reference to "Microsoft XML version 2.0"

Then write this code:

MSXML.XMLHTTPRequestClass objXmlHttp  = new MSXML.XMLHTTPRequestClass();
objXmlHttp.open("GET","http://website1.com/test?Success=http://www.success.com&Failure=http://www.failure.com", false, null, null);
string body = null;
objXmlHttp.send(body);
string strHTML = objXmlHttp.responseText;

Cheers,
S Sansanwal
0
 

Author Comment

by:garystark
ID: 11938912
OK, I'm trying to implement your suggestion.

First of all, you mention adding a reference to:
     "Microsoft XML version 2.0"
I see
     "Microsoft XML, v2.6"

Presumably that's OK?

Secondly, it doesn't compile.  I get this error message:

c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.cs(25): The type or namespace name 'MSXML' could not be found (are you missing a using directive or an assembly reference?)

Am I missing a "using"?  I have yet to figure out a reliable way of determining what "using" I am missing.

That's as far as I can go with your suggestion.

gary
0
 
LVL 7

Accepted Solution

by:
God_Ares earned 250 total points
ID: 11949923
if your doing xml stuff try this code

try
                  {

                        XmlTextReader r = new XmlTextReader("http://www.w3schools.com/xml/note.xml");                  
                        XmlDocument d = new XmlDocument();
                        d.Load(r);                              
                        XmlNode node = d.SelectSingleNode("/note/to");                  
                        if (node!=null) MessageBox.Show(node.InnerText);
                        r.Close();
                  }
                  catch(System.Net.WebException ex)
                  {
                        MessageBox.Show("Web exception  :"+ex.Message);
                  }
                  catch(System.Xml.XmlException ex)
                  {
                        MessageBox.Show("Xml exception :"+ex.Message);
                  }
                  catch(System.Exception ex)
                  {
                        MessageBox.Show("General exception :"+ex.Message);
                  }


but i think you just want some data read from a page,.. so here :

HttpWebRequest HttpWReq =
                        (HttpWebRequest)WebRequest.Create("http://"+textBox1.Text);

                  HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
                  
                  Stream receiveStream = HttpWResp.GetResponseStream();
                  System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
                  // Pipes the stream to a higher level stream reader with the required encoding format.
                  StreamReader readStream = new StreamReader( receiveStream, encode );
                  textBox2.Text = "\r\nResponse stream received.\r\n";
                  Char[] read = new Char[256];
                  // Reads 256 characters at a time.    
                  int count = readStream.Read( read, 0, 256 );
                  textBox2.Text += "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);
                        textBox2.Text += str;
                        count = readStream.Read(read, 0, 256);
                  }
                  


                  HttpWResp.Close();
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
designing in object programming 12 94
C# Desktop Application 3 54
Sort GridView by ID Descending 1 17
Winforms -- Capture CTRL+SHIFT+D at the form not working? 3 26
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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