SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    AdCaliber Magic2K2's Avatar
    Join Date
    Nov 2001
    Location
    Northern Virginia
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP equivalent of PHP's file_get_contents ?

    Does ASP have an equivalent to file_get_contents from PHP? This function essentially returns the output of a webpage.

    I am also looking for the Perl equivalent if anyone knows that one.

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is XMLHTTP mate. I take it your trying to retrieve HTML from a document and display it correctly. in asp you use XMLHTTP then you can abuse the response by editting the code before you display it.

    Although frowned apon, you can actually clone someone's web site using this method, and change the images/text to suit yours. As soon as they change there web site, yours updates.

    The correct reason for this is for news feeds, updatable information ( for information ), I use it for mailing. rather then having to stick to using CDOSYS which allows you to send a clone of a web page, you can use XMLHTTP. This will retrieve all information, all you to edit it, then use it as the HTML body of the e-mail you send.

    Hope this helps!

    Code:
     <%
     
     set XmlObj = Server.CreateObject("Microsoft.XMLHTTP")
     XmlObj.open "POST", "http://www.domain.com", false
     XmlObj.send
     
     formatdata = XmlObj.responseText
     
     formatdata = replace(formatdata,"<img src=""../images/logo.gif"">","<img src=""http://yourdomain.com/images/logo.gif"">")
     
     Response.write(formatdata)
     
     Set XmlObj = nothing
     %>


  3. #3
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to dig open the grave here, but since this is the first result for most searches related to this subject, I figured I'd share a more elegant solution:

    randomtools.net/asp-file_get_contents-and-file_put_contents-36.html

  4. #4
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gavin,
    Thanks for the info re: using the XMLHTTPRequest object to capture 3rd-party source code.

    How could I use this tool to capture the values of specific javascript variables in that 3rd-party source?

    Please advise. Thanks! Noah

  5. #5
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Noah,

    Using the same method, you can simply use a find and replace on the content that is returned.

    Do you have any information on the JS file your trying to access?


  6. #6
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gavin,
    Thanks for the prompt reply. I'm using the following to cut out the block of script but it's not definitely not ideal. I think I'll have to switch to RegEx to be sure I get the variables I need. Any thoughts on other approaches?

    <head>
    <%
    strURL = "http://www.homedepot.com/h_d1/N-5yc1vZ1xhc/R-100112584/h_d2/ProductDisplay?langId=-1&storeId=10051&catalogId=10053"

    set XmlObj = Server.CreateObject("Microsoft.XMLHTTP")
    XmlObj.open "POST", strURL, false
    XmlObj.send

    formatdata = XmlObj.responseText

    Dim nPos_Begining, nPos_End
    nPos_Begining = InStr(formatdata, "var CI_Pagetype") - 40
    nPos_End = InStr(formatdata, "var CI_ItemWeight") + 540
    strFormatFinal = Mid(formatdata, nPos_Begining, nPos_End)

    Set XmlObj = nothing

    Response.Write(strFormatFinal)

    %>

    </head>
    <body>
    <form name="HD_Data">
    <table>
    <tr>
    <td align="right" width="150"><b>Item ID: </b></td><td align="left"><input type="hidden" name="HD_ItemID" value=""><script language="javascript">document.write(CI_ItemID);</script></td>
    </tr>
    <tr>
    <td align="right" width="150"><b>Item Name: </b></td><td align="left"><script language="javascript">document.write(CI_ItemName);</script></td>
    </tr>
    <tr>
    <td align="right" width="150"><b>Category: </b></td><td align="left"><script language="javascript">document.write(CI_CatName);</script></td>
    </tr>
    <tr>
    <td align="right" width="150"><b>Manufacturer: </b></td><td align="left"><script language="javascript">document.write(CI_ItemMfr);</script></td>
    </tr>
    <tr>
    <td align="right" width="150"><b>Manufacturer ID: </b></td><td align="left"><script language="javascript">document.write(CI_ItemMfrNum);</script></td>
    </tr>
    <tr>
    <td align="right" width="150"><b>Item UPC: </b></td><td align="left"><script language="javascript">document.write(CI_ItemUPC);</script></td>
    </tr>
    <tr>
    <td align="right" width="150"><b>Item Weight: </b></td><td align="left"><script language="javascript">document.write(CI_ItemShipWeight);</script></td>
    </tr>
    </table>
    </form>


    </body>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •