Test Foro de elhacker.net SMF 2.1

Programación => .NET (C#, VB.NET, ASP) => Programación General => Programación Visual Basic => Mensaje iniciado por: qiqeroot en 27 Noviembre 2006, 13:23 PM

Título: Código de comprovación de url?
Publicado por: qiqeroot en 27 Noviembre 2006, 13:23 PM
bueno os esplico...ando buscando un source que compruebe si en una página
www.dominiocualkiera.com/noseke.html
el archivo html "noskee.html"compruebe que sta colgado y que te diga si o no
deve ser un código simple....e buscado por otros post y me e mirado bastantes manuales y explicaciones en vb pero no encuentro un código similar...que compruebe si hay "noseke.html" en el server y te responda si esta o no esta;D
Salu2
Gracias
Título: Re: Código de comprovación de url?
Publicado por: Hendrix en 27 Noviembre 2006, 15:09 PM
Puedes usar la API URLDownloadToFile y mirar si da error, si da error significa que no eixste, si no da error via libre....

Option Explicit

Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

Private Const ERROR_SUCCESS As Long = 0

Private Sub Form_Load()
Command1.Caption = "Download File"
End Sub


Private Sub Command1_Click()

Dim sourceUrl As String
Dim targetFile As String
Dim hfile As Long

sourceUrl = "http://www.mvps.org/vbnet/faq/main/fileloadtext.htm"
targetFile = "c:\deleteme.htm"

Label1.Caption = sourceUrl
Label2.Caption = targetFile

If DownloadFile(sourceUrl, targetFile) Then

hfile = FreeFile
Open targetFile For Input As #hfile
Text1.Text = Input$(LOF(hfile), hfile)
Close #hfile

End If

End Sub


Public Function DownloadFile(ByVal sURL As String, _
ByVal sLocalFile As String) As Boolean

Dim lngRetVal As Long

'if the API returns ERROR_SUCCESS (0),
'return True from the function
DownloadFile = URLDownloadToFile(0&, _
sURL, _
sLocalFile, _
0&, _
0&) = ERROR_SUCCESS

End Function


Fuente (http://www.expressnewsindia.com/c4/ex1/C937.html)

Salu2