ASP: Load image from a remote server

I needed to show the content of a remote page that require basic authentication into a different web site.
I started getting the text contents from an ASP page

Dim objSXHSet objSXH = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
URL = "
http://www.mysite.com/"
objSXH.open "GET", URL , False, "user", "password"
objSXH.send
If objSXH.status = 200 Then

response.Write objSXH.ResponseText
End If
Set objSXH = Nothing


Then I notice that images weren't displayed, so I parsed the HTML text replacing the image source path with a link to a custom page that get the image content

dim objSXHSet objSXH = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
URL = "
http://www.mysite.com/image.jpeg"
objSXH.open "GET", URL , False, "user", "password"
objSXH.send
If objSXH.status = 200 Then

response.BinaryWrite objSXH.ResponseBody
End If
Set objSXH = Nothing


Another sample is available on:
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q303982&ID=KB;EN-US;Q303982

Share on Google Plus

About Vittorio Pavesi

    Blogger Comment
    Facebook Comment

0 commenti: