Search code examples
asp-classic

read all elements from another page using classic ASP


Is there a way to read a another page's elements and grab the whole HTML code?

let's say for example i want to get all the HTML from this page : http://localhost/test3.html

Thank you!


Solution

  • Here's a function I use:

    function http_post (strUrl, data)
        ' call another URL (e.g. ASP or PHP script) via HTTP and POST. "data" should be GET-style parameter string or empty '
        dim xmlHttp
        Set xmlHttp = Server.Createobject("MSXML2.ServerXMLHTTP.6.0")
        With xmlHttp
            .Open "POST", strUrl, False
            .setRequestHeader "User-Agent", Request.ServerVariables("HTTP_USER_AGENT")
            .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
            .setRequestHeader "Content-Length", Len(data)
            .Send data
            if .Status < 400 then
                http_post = .responseText
            else
                ' do error logging here if you want '
                http_post = false
            end if
            .abort()
        End With
        set xmlHttp = Nothing
    end function