Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

need ASP -> C# translation help

Posted on 2004-08-30
3
Medium Priority
?
331 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 750 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 750 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

926 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