Bonjour !
j'ai un petit problème je vous explique j'aimerais télécharger un fichier binaire (une image) sur un site web (image dynamique). La vous me direz facile il y a "InetGet" oui effectivement mais en fait le site restreins l’accès au utilisateurs enregistré j'ai donc crée mon script de téléchargement de fichier (en me basant sur WinHttp) j'ai donc besoin d'ajouter un cookie de session a mon entête http voila un exemple de ce que j'ai fait :
#include <vidahttp.au3>
Code : Tout sélectionner
#include <vidahttp.au3>
Local $file = FileOpen("C:\Users\Vidada\test.png", 2)
$host = "www.lesite.com"
$page = "/dossierdelimage/image.php"
$test = Get_page($host,$page)
msgbox(0,"",$test)
FileWrite($file, $test)
FileClose($file)
vidahttp.au3 :
► Afficher le texte
Code : Tout sélectionner
Global $MainSocket
Global $MaxLength = 512; Maximum Length Of Text
$_HTTPUserAgent="AutoItScript/"&@AutoItVersion
Func Get_page($h,$p);Host Page Delimiteur
$timeout = 500;
TCPStartup()
Dim $ip = TCPNameToIP($h)
$MainSocket = TCPConnect($ip, 80)
If $MainSocket = -1 Then Exit MsgBox(16, "Error", "Unable to connect.")
$begin = TimerInit()
local $dif = TimerDiff($begin)
$command = "GET "&$p&" HTTP/1.1"&@CRLF
$command &= "Host: " &$h&@CRLF
$command &= "User-Agent: "&$_HTTPUserAgent&@CRLF
$command &= "Cookie: PHPSESSID=MON COOKIE"&@CRLF
$command &= "Connection: close"&@CRLF
$command &= ""&@CRLF
TCPSend($MainSocket, $command)
Global $reponse
While 1
$Data = TCPRecv($MainSocket, $MaxLength)
If TimerDiff($begin) > $timeout Then
msgbox(0,"","timer sortie")
return $reponse
ElseIf $Data <> "" Then
$reponse = $reponse & binary($Data)
$begin = TimerInit()
EndIf
WEnd
EndFunc
en gros mon code me sort une espèce de grande chaine hexadécimal et ne la transcrit pas en fichier image :S
PS: je ne savais pas comment détecter la fin du fichier alors j'ai fait un délais de non réception de données si vous pouviez m'aider a améliorer ça aussi ça serais super ^^
merci d'avance pour votre aide
Vidada