Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Preciso capturar dados de uma URL, mas como não consigo fazer isso usando o FileSystem Object, estou usando uma propriedade do XML.
Vejam o código abaixo:
<%
Arquivo = "http://10.8.4.157/acml/n_acml_b.txt"
Response.Write "Processando arquivo " & Arquivo & ":<br><br>"
Set ObjXmlHttp = Server.CreateObject("MsXml2.XMLHTTP")
ObjXmlHttp.Open "GET", Arquivo, False
' Send it on it's merry way.
ObjXmlHttp.Send
' Get the text of the response.
' This object is designed to deal with XML so it also has the following properties: ResponseBody, ResponseStream, and ResponseXML. We just want the text so I use:
StrHTML = ObjXmlHttp.ResponseText
' Trash our object now that I'm finished with it.
Set ObjXmlHttp = Nothing
Response.Write StrHTML
%>
O problema é que, se o arquivo existe, funciona direitinho. Mas se o arquivo não existe, retorna o seguinte erro:
Processando arquivo http://10.8.4.157/acml/n_acml_b.txt:
MSXML3.DLL error 'c00ce56e'
System error: -1072896658.
/robonovo/monta_acml.asp, line 14
O que eu preciso é de uma verificação da URL, podendo até me retornar uma variável que eu possa usar antes de processar um outro código.
É como se fosse um FileExists do FSO.
Alguma dica?
Use o "on error resume next"
<%on error resume nextArquivo = "http://10.8.4.157/acml/n_acml_b.txt"Response.Write "Processando arquivo " & Arquivo & ":<br><br>"Set ObjXmlHttp = Server.CreateObject("MsXml2.XMLHTTP")ObjXmlHttp.Open "GET", Arquivo, False' Send it on it's merry way.ObjXmlHttp.Send' Get the text of the response.' This object is designed to deal with XML so it also has the following properties: ResponseBody, ResponseStream, and ResponseXML. We just want the text so I use:StrHTML = ObjXmlHttp.ResponseText' Trash our object now that I'm finished with it.Set ObjXmlHttp = Nothing'Se ocorrer algum erroIf err Then StrHTML = "O arquivo não existe!"Response.Write StrHTML%>
OK? :huh:
Quero que, caso o URL não exista, um determinado valor seja armazenado em uma variável por exemplo, Site = NOTOK;Dá pra fazer isso?
Se ele não existir o que você quer que aconteça?