Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

RÉCUPERER LE TYPE D'UN SERVEUR HTTP VIA WINSOCK


Information sur la source

Catégorie :Réseau & Internet Niveau : Débutant Date de création : 27/10/2002 Date de mise à jour : 27/10/2002 11:36:45 Vu / téléchargé: 1 925 / 213

Note :
Aucune note

Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note


Description

Un simple code pour recuperer le type d'un serveur http et le temps de reponse , et qui donc par la meme occasion montre comment jouer avec la reception de donnée spécifique par winsock.
C'est simple, mais ca peut servir.
Pour info, touts les serveurs ne renvoient pas toujours dans leurs headers leurs type, par exemple yahoo.fr , mais ce type d'exemple est rare (sur les quelques tests que j'ai fait) .
Et sur votre form, il faut 3 textbox nommées "Host" , "srvtype" et "anstime" , un controle winsock nommé ws et un command button "command1" .
 

Source

  • Private Declare Function GetTickCount Lib "kernel32" () As Long
  • Dim answert As Long
  • Dim hblisten As Boolean
  • Dim buffer As String
  • Private Sub Command1_Click()
  • buffer = ""
  • hblisten = True
  • If Host.Text <> "" Then
  • ws.Close
  • ws.Connect "" & Host.Text & "", 80
  • answert = GetTickCount
  • Else
  • MsgBox "Vous n'avez pas entré de serveur", vbCritical
  • End If
  • End Sub
  • Private Sub ws_connect()
  • If hblisten = True Then
  • ws.SendData "GET http://" & Host.Text & "/ HTTP/1.0" & vbCrLf & _
  • "Host: " & Host.Text & "" & vbCrLf & vbCrLf
  • End If
  • End Sub
  • Private Sub ws_DataArrival(ByVal bytesTotal As Long)
  • Dim data As String
  • ws.GetData data
  • buffer = buffer & data
  • If hblisten = True Then
  • If hb_str_in_str(buffer, "Server: ", vbCrLf) <> "" Then
  • srvtype.Text = hb_str_in_str(buffer, "Server: ", vbCrLf)
  • anstime.Text = "réponse du serveur en " & CDec((GetTickCount - answert) / 1000) & " secondes"
  • ws.Close
  • hblisten = false
  • Else
  • srvtype.Text = "Can't get server type"
  • anstime.Text = "réponse du serveur en " & CDec((GetTickCount - answert) / 1000) & " secondes"
  • ws.Close
  • hblisten = false
  • End If
  • End If
  • End Sub
  • Public Function hb_str_in_str(source As String, stravant As String, strapres As String)
  • If InStr(1, source, stravant) > 0 Then
  • If InStr((InStr(1, source, stravant)), source, strapres) > 0 Then
  • If Mid(source, (InStr(1, source, stravant) + Len(stravant)), InStr((InStr(1, source, stravant) + Len(stravant)), source, strapres) - (InStr(1, source, stravant) + Len(stravant))) <> "" Then
  • hb_str_in_str = Mid(source, (InStr(1, source, stravant) + Len(stravant)), InStr((InStr(1, source, stravant) + Len(stravant)), source, strapres) - (InStr(1, source, stravant) + Len(stravant)))
  • End If
  • End If
  • End If
  • End Function
Private Declare Function GetTickCount Lib "kernel32" () As Long
Dim answert As Long
Dim hblisten As Boolean
Dim buffer As String

Private Sub Command1_Click()
buffer = ""
hblisten = True
If Host.Text <> "" Then
ws.Close
ws.Connect "" & Host.Text & "", 80
answert = GetTickCount
Else
MsgBox "Vous n'avez pas entré de serveur", vbCritical
End If
End Sub


Private Sub ws_connect()
If hblisten = True Then
ws.SendData "GET http://" & Host.Text & "/ HTTP/1.0" & vbCrLf & _
            "Host: " & Host.Text & "" & vbCrLf & vbCrLf
End If
End Sub

Private Sub ws_DataArrival(ByVal bytesTotal As Long)
Dim data As String
ws.GetData data
buffer = buffer & data
If hblisten = True Then
 If hb_str_in_str(buffer, "Server: ", vbCrLf) <> "" Then
  srvtype.Text = hb_str_in_str(buffer, "Server: ", vbCrLf)
  anstime.Text = "réponse du serveur en " & CDec((GetTickCount - answert) / 1000) & " secondes"
    ws.Close
  hblisten = false
  Else
  srvtype.Text = "Can't get server type"
  anstime.Text = "réponse du serveur en " & CDec((GetTickCount - answert) / 1000) & " secondes"
    ws.Close
  hblisten = false
 End If

End If
 End Sub
 
 Public Function hb_str_in_str(source As String, stravant As String, strapres As String)
If InStr(1, source, stravant) > 0 Then
If InStr((InStr(1, source, stravant)), source, strapres) > 0 Then
If Mid(source, (InStr(1, source, stravant) + Len(stravant)), InStr((InStr(1, source, stravant) + Len(stravant)), source, strapres) - (InStr(1, source, stravant) + Len(stravant))) <> "" Then
hb_str_in_str = Mid(source, (InStr(1, source, stravant) + Len(stravant)), InStr((InStr(1, source, stravant) + Len(stravant)), source, strapres) - (InStr(1, source, stravant) + Len(stravant)))
End If
End If
End If
End Function

Conclusion

en esperant que ca puisse servir
 

Fichier Zip

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

Commentaires et avis

signaler à un administrateur
Commentaire de cosmic le 11/11/2002 23:54:23

Je trouve ta source interressente...
J'ai un peu de mal a la comprendre.

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Janvier 2009
LMMJVSD
   1234
567891011
12131415161718
19202122232425
262728293031 

Consulter la suite du CalendriCode



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel BAÏSE, Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,312 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.