j'ai fait une fonction pour envoyer un fichier en HTTP Post, mais après quelques teste, j'ai l'impression qu'elle ne marche pas. En effet, je n'obtient pas de réponse du serveur (avec HTTPRead) La voici:
Code : Tout sélectionner
Func _HTTPPostFile($host, $page, $socket = -1, $file = "", $champ = "file", $extradata)
Dim $command
If $socket == -1 Then
If $_HTTPLastSocket == -1 Then
SetError(1)
Return
EndIf
$socket = $_HTTPLastSocket
EndIf
$contenttype = _HTTPPost_contenttype($file)
Dim $boundary = "-----------------------------" + _TimeToTicks(@HOUR, @MIN, @SEC)
$fileread = _HTTPEncodeString(StringTrimLeft(FileRead(FileOpen($file, 16)),2))
FileClose($fileread)
$extradata = _HTTPEncodeString($extradata)
$multipost_cmd = "--"&$boundary&@CRLF
$multipost_cmd &= "Content-Disposition: form-data; name="""&$champ&"""; filename=""" & $file & """" &@CRLF
$multipost_cmd &= "Content-Type: "&$contenttype&@CRLF&@CRLF
$multipost_cmd &= $fileread&@CRLF
$multipost_cmd &= "--"&$boundary&"--"
Dim $datasize = StringLen($multipost_cmd) + StringLen($extradata)
$command = "POST "&$page&" HTTP/1.1"&@CRLF
$command &= "Host: " &$host&@CRLF
$command &= "User-Agent: "&$_HTTPUserAgent&@CRLF
$command &= "Connection: close"&@CRLF
$command &= "Content-Type: multipart/form-data; boundary="&$boundary&@CRLF
$command &= "Content-Length: "&$datasize&@CRLF
$command &= ""&@CRLF
$command &= $extradata&@CRLF
$command &= $multipost_cmd
If FileExists("output.txt") Then FileDelete("output.txt")
$file = FileOpen("output.txt", 1)
FileWrite($file, $command)
FileClose($file)
Dim $bytessent = TCPSend($socket, $command)
If $bytessent == 0 Then
SetExtended(@error)
SetError(2)
return 0
EndIf
SetError(0)
Return $bytessent
EndFunc
Func _HTTPPost_contenttype($file = "")
$fileextension = StringRight($file,4)
Switch $fileextension
Case ".txt"
$contenttype = "text/plain"
Case ".jpg"
$contenttype = "image/jpg"
Case ".png"
$contenttpye = "image/png"
Case Else
$contenttype = "application/octet-stream"
EndSwitch
Return $contenttype
EndFunc
Voyez vous une erreur quelque part ?
Merci d'avance,
@++



