SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 27
  1. #1
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XMLHttp download and use a file.

    I have a question which I hope you can help me with.

    I have recently started to look after a website which has been setup to do the following.

    We have intranet1, intranet2 and internet3.

    1 is our intranet site, 2 is a backup of 3 and located on our intranet and 3 is our main public website.

    1 and 2 are both hosted on the same network, 3 is on an external network.

    Here is what I need to do, internet3 has a page where jobs are loaded dynamically from XML and XSL files and it is backed up every night to intranet2.

    intranet1 then reads the XML and XSL file from intranet2 and updates the intranet jobs site, this means the intranet jobs site is always one day out of date.
    What I would like to do is get intranet1 to check the XML and XSL files on website3 whenever the jobs page is requested so that the intranet1 site is always up to date.
    I have been reading about how to do this and I think XMLHttp would be the way to do this but I have very little ASP knowledge just now.

    Can anyone help.

    O.
    Failure happens, its what you learn from it that is important!

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have the right idea. You can use variants of XMLHTTP to download xml files across domains.

    Does the webserver hosting intranet1 have access via http to website3? If so then it should be very simple.

    Code:
    <&#37;
    Set oXH = Server.CreateObject("MSXML2.ServerXMLHTTP")
    
    ' get jobs.xml from website3
    oXH.open "GET", "http://www.website3.com/xml/jobs.xml", False
    oXH.send
    
    If oXH.status <> 200 Then
    	Response.Write "Cannot connect to server"
    	Response.End
    End If
    
    Set oJobsXML = oXH.responseXML
    
    
    ' get jobs.xsl from website3
    oXH.open "GET", "http://www.website3.com/xml/jobs.xsl", False
    oXH.send
    
    If oXH.status <> 200 Then
    	Response.Write "Cannot connect to server"
    	Response.End
    End If
    
    Set oJobsXSL = oXH.responseXML
    
    
    
    ' do something with jobsXML and jobsXSL
    Response.Write oJobsXML.transformNode(oJobsXSL)
    %>

  3. #3
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help!!

    I have copied your code and changed the websites for ip address as it was unable to resolve the address. This now brings up the error:

    msxml3.dll error '80072efd'

    A connection with the server could not be established

    /test/owain.asp, line 6


    I guess it sounds like the intranet server doesnt have http access to the website. Would this be correct? If so, I will speak to the network team and get them to change this.

    Thanks again for your help!


    edit: One other question, is the oXH a standard asp function or have you just created it?

    O.
    Failure happens, its what you learn from it that is important!

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oXH is a ServerXMLHTTP object that is created in the first line of code. In your case it creates a MSXML3 object (as you can see by the error you get) - check out the microsoft site for documentation on msxml if you need more.

  5. #5
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    Would you say the error message Im getting is due to a server permission issue?

    O.
    Failure happens, its what you learn from it that is important!

  6. #6
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Possibly.

    It's very easy to check. On the server machine, open a web browser and type in the url you have in the oXH.open line. See what happens.

  7. #7
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That could be a problem, I dont have server access I will need to speak to our network engineers I guess...

    O.
    Failure happens, its what you learn from it that is important!

  8. #8
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I have accessed the server and it does have internet access but when I try and call the file from within my asp page I still get the message "A connection with the server could not be established" could this be blocked by the external hosting company?

    O.
    Failure happens, its what you learn from it that is important!

  9. #9
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure about that.

    I think that a serverxmlhttp request to http://www.mysite.com is treated exactly the same as a browser request...so if the browser works there should be no reason why the request doesn't...unless you are using proxies or the site is password protected (in which case you'd configure the serverxmlhttp object differently).

  10. #10
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ye, we do use a proxy here.....could you give me some pointers how to configure the xmlhttp object to handle a proxy.....

    Thanks,
    O.
    Failure happens, its what you learn from it that is important!

  11. #11
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK I've never set a proxy with serverxmlhttp but my best guess is this:

    Add this line between oXH.open and oXH.send:
    oXH.setProxy 2, "myProxyServer"

    (change myProxyServer to the url or ip of your proxy)

    If your proxy uses credentials:
    oXH.setProxy 2, "myProxyServer"
    oXH.setProxyCredentials "myUsername", "myPassword"


    Have a look at this page if you need reference:
    http://msdn2.microsoft.com/en-us/library/ms754586.aspx

  12. #12
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We are getting there,
    The page is now loading but instead of the results I am getting an error message which I just can't seem to fix, I have search the net and forum and nothing.

    Microsoft VBScript runtime error '800a01a8'

    Object required: ''

    /news/vacancies.asp, line 110


    The code is:
    Code:
    <&#37;
    Set oXH = Server.CreateObject("MSXML2.ServerXMLHTTP")
    
    ' get jobs.xml from live website
    
    oXH.open "GET", "URLtoXMLFile/vacancies.xml",False
    xmlHttp.setProxy 2, "net1:8080"
    oXH.send
    
    If oXH.status <> 200 Then
    	Response.Write "Cannot connect to server"
    	Response.End
    End If
    
    Set oJobsXML = oXH.responseXML
    
    
    ' get jobs.xsl live website
    oXH.open "GET", "URLtoXSLFile/vacancieslist.xsl",False
    xmlHttp.setProxy 2, "net1:8080"
    oXH.send
    
    If oXH.status <> 200 Then
    	Response.Write "Cannot connect to server"
    	Response.End
    End If
    
    Set oJobsXSL = oXH.responseXML
    
    
    
    ' do something with jobsXML and jobsXSL
    Response.Write oJobsXML.transformNode(oJobsXSL)
    %>
    The line I am getting the error on is in Bold.

    Thanks,
    O.
    Failure happens, its what you learn from it that is important!

  13. #13
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can anyone point me in the right direction?

    O.
    Failure happens, its what you learn from it that is important!

  14. #14
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your object is called oXH, not xmlHttp.

    Change the line to
    oXH.setProxy (etc)

  15. #15
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry I meant to post I had changed that and I now get this error:

    Server object error 'ASP 0177 : 800401f3'

    Server.CreateObject Failed

    /news/vacancies.asp, line 105

    Invalid ProgID. For additional information specific to this message please visit the Microsoft Online Support site located at: http://www.microsoft.com/contentredirect.asp.


    Line 105: Set oXH = Server.CreateObject("MSXML3.ServerXMLHTTP")


    Code:
    <&#37;
    Set oXH = Server.CreateObject("MSXML3.ServerXMLHTTP")
    
    ' get jobs.xml from  website
    
    oXH.open "GET", "http://website/vacancies.xml",False
    oXH.setProxy 2, "net1:8080"
    oXH.send
    
    If oXH.status <> 200 Then
    	Response.Write "Cannot connect to server"
    	Response.End
    End If
    
    Set oJobsXML = oXH.responseXML
    
    
    ' get jobs.xsl from  website
    oXH.open "GET", "http://website/vacancieslist.xsl",False
    oXH.setProxy 2, "net1:8080"
    oXH.send
    
    If oXH.status <> 200 Then
    	Response.Write "Cannot connect to server"
    	Response.End
    End If
    
    Set oJobsXSL = oXH.responseXML
    
    
    
    
    ' do something with jobsXML and jobsXSL
    Response.Write oJobsXML.transformNode(oJobsXSL)
    %>
    Thanks for your continued help!

    O.
    Failure happens, its what you learn from it that is important!

  16. #16
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    2 not 3

    Set oXH = Server.CreateObject("MSXML2.ServerXMLHTTP")

  17. #17
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guess what....still getting an error:

    Microsoft VBScript runtime error '800a01b6'

    Object doesn't support this property or method: 'setProxy'

    /news/vacancies.asp, line 110


    Line 110: oXH.setProxy 2, "net1:8080"


    Thanks,
    O.
    Failure happens, its what you learn from it that is important!

  18. #18
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should work, MS says that setProxy is implemented in serverxmlhttp in msxml3 and up.

    post all your code again.

  19. #19
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the code again,
    Code:
    <&#37;
    Set oXH = Server.CreateObject("MSXML2.ServerXMLHTTP")
    
    ' get jobs.xml from live website
    
    oXH.open "GET", "http://Website_Address/vacancies.xml",False
    oXH.setProxy 2, "net1:8080"
    oXH.send
    
    If oXH.status <> 200 Then
    	Response.Write "Cannot connect to server"
    	Response.End
    End If
    
    Set oJobsXML = oXH.responseXML
    
    
    ' get jobs.xsl from live website
    oXH.open "GET", "http://Website_Address/vacancieslist.xsl",False
    oXH.setProxy 2, "net1:8080"
    oXH.send
    
    If oXH.status <> 200 Then
    	Response.Write "Cannot connect to server"
    	Response.End
    End If
    
    Set oJobsXSL = oXH.responseXML
    
    
    
    ' do something with jobsXML and jobsXSL
    Response.Write oJobsXML.transformNode(oJobsXSL)
    %>
    Cheers,
    O.
    Failure happens, its what you learn from it that is important!

  20. #20
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK I got it working, I forgot that msxml has some funny progid's and unless you are extremely specific you end up using an older version. Change this:

    Set oXH = Server.CreateObject("MSXML2.ServerXMLHTTP")
    to
    Set oXH = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")

    here is the code I tested, I got the proxy from http://www.freshproxylist.org/
    Code:
    <&#37;
    Set oXH = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
    
    oXH.open "GET", "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml",False
    oXH.setProxy 2, "221.238.196.48:80"
    oXH.send
    
    If oXH.status <> 200 Then
    	Response.Write "Cannot connect to server"
    	Response.End
    End If
    
    Set oJobsXML = oXH.responseXML
    
    Response.Write oJobsXML.xml
    Response.End
    %>

  21. #21
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does the If oXH.status <> 200 do? Because my program is now going in to that if statement and showing the "Cannot connect to server" error....

    Thanks for your help!!

    O.
    Failure happens, its what you learn from it that is important!

  22. #22
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It means that the server returned an error (404, 401, 403) or something.

    Write out the error:
    If oXH.status <> 200 Then
    Response.Write "Cannot connect to server (" & oXH.status & ")"
    Response.End
    End If

    and see what you get

  23. #23
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Jim,
    Its a 407 error which is to do with authentication so I have added an authentication line :

    Code:
    oXH.open "GET", "http:/website/vacancies.xml",False
    oXH.setProxy 2, "net1:8080"
    oXH.setProxyCredentials "MyUserName", "myPassword"
    oXH.send
    But now I get the following error message:

    msxml4.dll error '80072eef'

    The login request was denied

    /news/vacancies.asp, line 112

    and line 112 is oXH.send

    Owain.
    Failure happens, its what you learn from it that is important!

  24. #24
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the proxy require authentication, or the website that you are getting the xml from, or both?

    You'd have to log into both separately if so - logging into the website is done using the oXH.Open method.

  25. #25
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have already for the oXH.open method within the code

    oXH.open "GET", "http:/website/vacancies.xml",False


    O.
    Failure happens, its what you learn from it that is important!


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
  •