When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
Technology Jobs
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs

The 4 Guys Present: ASPFAQs.com

Jump to a FAQ
Enter FAQ #:
..or see our 10 Most Viewed FAQs.

4GuysFromRolla.com : ASP FAQS : Networking


Question:

How can I treat some other web page as data on my own site?


[Print this FAQ]

Answer: The best way to do this is to use the ServerXMLHTTP object which is included in most version of IIS and/or is downloadable from the Microsoft site.

For a quick introduction to its capabilities, click here.

Perhaps the most important point not noted there is how to "hit" a site and send simulated <FORM> data.

If the site expects the data as part of the URL (that is, if a QueryString is normally used), then it's easy: Just use the full URL with querystring as part of the URL in the OPEN command:

objSrvHTTP.open "GET","http://www.aspmessageboard.com/forum/advanced.asp?F=27", False


But if you need to simulate a <FORM METHOD=POST> (that is, if the page you are hitting uses the equivalent of Request.Form to read the information), then you need to include the data as part of the Send method.

And the format you need to use is simple: Identical to the usual form of a query string! So, for example, to simulate the posting of a form such as this one:

<FORM Action="http://www.foo.com?process.asp" Method=Post>
<INPUT Name="person">
<INPUT Name="email">
<INPUT Type=Submit>
</FORM>


you would write something like this:

Dim info
info = "person=" & person & "&email=" & email

objSrvHTTP = Server.CreateObject ("MSXML2.ServerXMLHTTP")
objSrvHTTP.open "POST","http://www.foo.com/process.asp",False
objSrvHTTP.send info
...







Most of the rest of the information in this FAQ is obsolete. It has been retained for those who might not have access to current versions of IIS.



A typical version of this question might sound something like this:

Is there an easy way have an ASP script get an html file and pull data out of it? For example, could I have a script that goes to www.cnn.com (with their permission of course) and grabs the headlines so I can re-display them on my webpage?

The answer is: It's really easy, but... Unfortunately, you can't do it from "raw" ASP. You need a component to do the needed HTTP "spoofing" (that is, to pretend that it is just another web browser asking for info from the site). You can write your own component (and it's not overwhelmingly difficult, especially in Java with all the convenient I/O classes available, but it does require a knowledge of the HTTP protocol, at a minimum), but most people will find it a lot easier to purchase one of the third party components designed for this purpose.

Two components I know of are:

AspTear from Alpha Sierra Papa

AspHTTP from Server Objects.

Scott points out that there are articles on 4GuysFromRolla about using AspTear:

Grabbing Information from other Servers
Grabbing Table Columns from Other Web Pages


Added by Richard Lowe on October 25th, 2000...

You can also use the freely availabe XMLHTTP component from Microsoft. An example of using this component can be seen below:

<%

Function GetHTML(strURL)
  Dim objXMLHTTP, strReturn
  Set objXMLHTTP = SErver.CreateObject("Microsoft.XMLHTTP")

  objXMLHTTP.Open "GET", strURL, False
  objXMLHTTP.Send

  strReturn = objXMLHTTP.responseText
  Set objXMLHTTP = Nothing

  GetHTML = strReturn
End Function

' Write it:
Response.Write GetHTML("http://www.aspfaqs.com/")

' Download it:
Response.ContentType = "application/x-msdownload"
Response.AddHeader "Content-Disposition", "filename=Something.asp"
Response.BinaryWrite GetHTML("http://www.aspfaqs.com/")

%>

You can download the XMLHTTP component through:
MDAC 2.6
-or-
the MSXML Beta!

UPDATE!


Those two links appear to no longer be valid. Microsoft just loves reorganizing the MSDN site about every 3 to 6 months and invalidating any links you might have. As of 14 September 2001, at least, this link appears to get to the right place:
http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/001/680/msdncompositedoc.xml Good luck with it!


FAQ posted by Bill Wilkinson at 10/16/2000 7:14:31 PM to the Networking category. This FAQ has been viewed 91,306 times.

Do you have a FAQ you'd like to suggest? Suggestions? Comments? If so, send it in! Also, if you'd like to be a FAQ Admin (creating/editing FAQs), let me know! If you are looking for other FAQs, be sure to check out the 4Guys FAQ and Commonly Asked Messageboard Questions!

Most Viewed FAQs:

1.) How can I format numbers and date/times using ASP.NET? For example, I want to format a number as a currency. (761643 views)
2.) I am using Access and getting a 80004005 error (or a [Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot open the file '(unknown)' error) when trying to open a connection! How can I fix this problem? (207777 views)
3.) How can I convert a Recordset into an array? Also, how can I convert an array into a Recordset? (202549 views)
4.) How can I quickly sort a VBScript array? (196039 views)
5.) How can I find out if a record already exists in a database? If it doesn't, I want to add it. (156019 views)
6.) How do I display data on a web page using arrays instead of Do...While...MoveNext...???... (152331 views)
7.) When I get a list of all files in a directory via the FileSystemObject, they aren't ordered in any reasonable way. How can I sort the files by name? Or by size? Or by date created? Or... (140381 views)
8.) For session variables to work, must the Web visitor have cookies enabled? (110162 views)
9.) Can I send emails without using CDONTS? (107083 views)
10.) How can I take the result of a SELECT...MULTIPLE or a group of same-named checkboxes and turn it into a query? That is, if the user selects 3 answers, how can I construct a query that looks for all 3? (106308 views)
Last computed at 9/17/2007 3:22:00 AM

Software Developer / Programmer - Distributed Systems (NYC)
Next Step Systems
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume


ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article