Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

need ASP -> C# translation help

Posted on 2004-08-30
3
Medium Priority
?
330 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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…

715 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