Solved

need ASP -> C# translation help

Posted on 2004-08-30
3
328 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 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

759 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