Solved

need ASP -> C# translation help

Posted on 2004-08-30
3
322 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

16 Experts available now in Live!

Get 1:1 Help Now