Link to home
Start Free TrialLog in
Avatar of Chris Andrews
Chris AndrewsFlag for United States of America

asked on

including content from another site


Hello,

I do most of my stuff in php, I don't know asp.

My goal is to deliver content to other sites, passing a little data back to myself for tracking.  With php, I can do this with a 'file_get_contents' statement.

I asked on this asp forum how I could do this same thing with asp, and received an answer from j2nku

https://www.experts-exchange.com/questions/21062781/delivering-content-rewrite-php-script-into-asp-code.html

The answer was to do this:

<%
rqst=Request.ServerVariables("HTTP_HOST")&Request.ServerVariables("PATH_INFO")
url="http://www.onyoursite.com/data/cxc.htp?rqst="&rqst
set Http = server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
Http.Open "GET", url, False
Http.Send
Dim resptext
resptext = Http.ResponseText
response.write (resptext)
Set Http = nothing
%>

and that works.

The question I have now: I have more than one piece of content.  Some webmasters may include several pieces of content on their pages.  If I include the above script on one page, just changing the url, I get an error:

------
Microsoft VBScript compilation error '800a0411'
Name redefined
/christophera/test.asp, line 22
Dim resptext
----^

Obviously I need to change the name of some variables or something to differentiate one piece of code from another. Can you show me what I need to change in this code when I change the url for additional content?  The code that caused the error above is below:           Thank you.

<%
rqst=Request.ServerVariables("HTTP_HOST")&Request.ServerVariables("PATH_INFO")
url="http://www.onyoursite.com/data/cxc.htp?rqst="&rqst
set Http = server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
Http.Open "GET", url, False
Http.Send
Dim resptext
resptext = Http.ResponseText
response.write (resptext)
Set Http = nothing
%>
<BR><BR>
<%
rqst=Request.ServerVariables("HTTP_HOST")&Request.ServerVariables("PATH_INFO")
url="http://www.onyoursite.com/data/wwc.htp?rqst="&rqst
set Http = server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
Http.Open "GET", url, False
Http.Send
Dim resptext
resptext = Http.ResponseText
response.write (resptext)
Set Http = nothing
%>
<BR><BR>
<%
rqst=Request.ServerVariables("HTTP_HOST")&Request.ServerVariables("PATH_INFO")
code="euuk"
url="http://www.onyoursite.com/data/tdl.htp?code="&code&"&rqst="&rqst
set Http = server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
Http.Open "GET", url, False
Http.Send
Dim resptext
resptext = Http.ResponseText
response.write (resptext)
Set Http = nothing
%>
Avatar of Chris Andrews
Chris Andrews
Flag of United States of America image

ASKER

oh, and if there is some way to do error supression... so if for some reason this script does not connect to the server, there is no error report, no content, just empty, that would be beneficial.  

Thank you,     Chris
Avatar of ap_sajith
ap_sajith

I have modified your code a bit as follows.. I havent tested it though.. it should work as expected.. let me know if it throws any errors..

<%
' Declare all variables
'-------------------------
Dim resptext,rqst,url,code
' First url
'----------
rqst=Request.ServerVariables("HTTP_HOST")&Request.ServerVariables("PATH_INFO")
url="http://www.onyoursite.com/data/cxc.htp?rqst="&rqst
resptext = getContent(url)
response.write (resptext) & "<br><br>"

' Second url
'--------------
rqst=Request.ServerVariables("HTTP_HOST")&Request.ServerVariables("PATH_INFO")
url="http://www.onyoursite.com/data/wwc.htp?rqst="&rqst
resptext = getContent(url)
response.write (resptext) & "<br><br>"

' Third url
'-----------
rqst=Request.ServerVariables("HTTP_HOST")&Request.ServerVariables("PATH_INFO")
code="euuk"
url="http://www.onyoursite.com/data/tdl.htp?code="&code&"&rqst="&rqst
resptext = getContent(url)
response.write (resptext) & "<br><br>"
%>


<%
function getContent(byVal sURL)
Dim oXML, strData  
Set oXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
oXML.Open "GET", sURL, false   ' true would specify an asynchronous request
Call oXML.Send()

'Wait for up to 3 seconds if we've not gotten the data yet
'-----------------------------------------------------------------
If oXML.readyState <> 4 then
      oXML.waitForResponse 3
End If

If Err.Number <> 0 then
      strData = "An error occured while processing this request..."
Else
      If (oXML.readyState <> 4) Or (oXML.Status <> 200) Then
            'Abort the XMLHttp request
            '-------------------------------
            oXML.Abort            
            strData = "Problem communicating with remote server..."
    Else
      strData = oXML.ResponseText
    End If
End If
set oXML=nothing
getContent=strData
end function
%>

Cheers!!

Hi ap_sajith,

um, actually, I would need each of these to act independently.  I won't know what content the webmaster will use, or if they will use one, two, or several on the same page.

In other words, I need to be able to offer each section as an independent piece, but they have to be able to function on the same page if a webmaster puts them on the same page.

Does that make sense, I don't know if I am explaining that well.  

The webmaster might put this on thier page:

<%
rqst=Request.ServerVariables("HTTP_HOST")&Request.ServerVariables("PATH_INFO")
url="http://www.onyoursite.com/data/cxc.htp?rqst="&rqst
set Http = server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
Http.Open "GET", url, False
Http.Send
Dim resptext
resptext = Http.ResponseText
response.write (resptext)
Set Http = nothing
%>

or they might put that and also another, or several, with different urls.  I need to be able to give them a code snippet like this for each url, but have them not interfere with each other if used together.
Would it be OK if all the Webmasters append their URL's to a text file?

Cheers!!
ASKER CERTIFIED SOLUTION
Avatar of ap_sajith
ap_sajith

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi ap_sajith,

I'm sorry, I know you are doing a lot of work on this, I don't seem to be making myself understood.

What I actually need are seperate pieces of code.  Maybe this is not possible in asp?

I need it set up so that a webmaster can do this:

<%
rqst=Request.ServerVariables("HTTP_HOST")&Request.ServerVariables("PATH_INFO")
url="http://www.onyoursite.com/data/cxc.htp?rqst="&rqst
set Http = server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
Http.Open "GET", url, False
Http.Send
Dim resptext
resptext = Http.ResponseText
response.write (resptext)
Set Http = nothing
%>

on one part of their page.  Then they might do a <br>, or they might make a table, or have text... then whereever they want on the page, they might put:

<%
rqst=Request.ServerVariables("HTTP_HOST")&Request.ServerVariables("PATH_INFO")
url="http://www.onyoursite.com/data/wwc.htp?rqst="&rqst
set Http = server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
Http.Open "GET", url, False
Http.Send
Dim resptext
resptext = Http.ResponseText
response.write (resptext)
Set Http = nothing
%>


Right now that causes an error.  Is there a way for me to differeniate those codes, so that if a webmaster uses more than one piece of code, they don't interfere with each other?  

For example, the codes above are for the 'world wide clock' and the 'currency exchange calculator'.  A webmaster will come to my site, and they might just want the clock.  They will grab the asp code, put it on their page, and the clock will appear there.

Another webmaster will come to the site.  They copy the code for the clock and put it where they want on a page.  They want to have the calculator too.  They come back to my site, copy the code for the currency calculator, and will put that code on the page where they want the calculator to be.  

In the second case, they would get an error.  

I need a way to differientiate the code snippets so they don't interfere with each other.  And it needs to be real simple, just copy the code and put it on your site where you want each item to be.

The error I get when more than one item is used is 'name redefined'.  Can I give each code snippet a unique name so no names are redefined?  I am just guessing as I don't know how asp works.

Thank you for all the work you are putting into this!!

oh, ok, I figured it out.

If I change the word 'resptext' in the code, to an abreviation of the content, ie, 'cxc' for the currency calculator, and 'wwc' for the world clock, then the code snippets can be used on the same page.  Like this:


<%
rqst=Request.ServerVariables("HTTP_HOST")&Request.ServerVariables("PATH_INFO")
url="http://www.onyoursite.com/data/wwc.htp?rqst="&rqst
set Http = server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
Http.Open "GET", url, False
Http.Send
Dim wwc
wwc = Http.ResponseText
response.write (wwc)
Set Http = nothing
%>

and:

<%
rqst=Request.ServerVariables("HTTP_HOST")&Request.ServerVariables("PATH_INFO")
url="http://www.onyoursite.com/data/cxc.htp?rqst="&rqst
set Http = server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
Http.Open "GET", url, False
Http.Send
Dim cxc
cxc = Http.ResponseText
response.write (cxc)
Set Http = nothing
%>

However, I still could use a way to suppress an error report.  If my server is down or can't be reached for any reason, instead of a "can't resolve url", is there a way to make it so nothing is reported, so it doesn't mess up the users page? The results should be nothing if the server can't be reached, not an error message.

Chris
SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Thank you.  Yes, the way I will need to do this is by handing out code snippets, so repeated code will be necessary to keep things simple.

The On Error Resume Next works perfectly.

I recognize all the work ap_sajith put into this, though not exactly what I was looking for I learned from it :)  And I thank acperkins for the error suppression code.  I will split the points here 400/100, I hope that is acceptable.