Jump to content

Show file upload percent progression (_HTTPPost_File() function)


 Share

Recommended Posts

@Malharhak

You can't get the percentage with the function given in the UDF in so far as it sends all your data at once.

You need to split the data you want to send (e.g: by 1024 bytes), then make a while until you have finished to send your data.

In this while you can update the percentage of the data sent.

Br, FireFox.

Link to comment
Share on other sites

You can do like this :

Func _HTTPPost($host, $page, $socket = -1, $data = "")
Local $command

If $socket == -1 Then
If $_HTTPLastSocket == -1 Then
Return SetError(1)
EndIf
$socket = $_HTTPLastSocket
EndIf

Local $datasize = StringLen($data)

$command = "POST " & $page & " HTTP/1.1" & @CRLF
$command &= "Host: " & $host & @CRLF
$command &= "User-Agent: " & $_HTTPUserAgent & @CRLF
$command &= "Connection: close" & @CRLF
$command &= "Content-Type: application/x-www-form-urlencoded" & @CRLF
$command &= "Content-Length: " & $datasize & @CRLF
$command &= "" & @CRLF

TCPSend($socket, $command)

Local $bytessent = 0

While $bytessent < $datasize
$bytessent += TCPSend($socket, StringMid($data, 1 + $bytessent, 1024)) ;1+ :stringmid starts at 1
WEnd

TCPSend($socket, @CRLF)

If $bytessent == 0 Then
Return SetError(2, @error, 0)
EndIf

Return SetError(0, 0, $bytessent)
EndFunc   ;==>_HTTPPost

The best would to use winapi functions to read the file at X offset; because you want to send the data of a file, right?

Br, FireFox.

Link to comment
Share on other sites

On 11/14/2012 at 11:24 AM, &#x27;FireFox said:

You can do like this :

Func _HTTPPost($host, $page, $socket = -1, $data = "")
Local $command

If $socket == -1 Then
If $_HTTPLastSocket == -1 Then
Return SetError(1)
EndIf
$socket = $_HTTPLastSocket
EndIf

Local $datasize = StringLen($data)

$command = "POST " & $page & " HTTP/1.1" & @CRLF
$command &= "Host: " & $host & @CRLF
$command &= "User-Agent: " & $_HTTPUserAgent & @CRLF
$command &= "Connection: close" & @CRLF
$command &= "Content-Type: application/x-www-form-urlencoded" & @CRLF
$command &= "Content-Length: " & $datasize & @CRLF
$command &= "" & @CRLF

TCPSend($socket, $command)

Local $bytessent = 0

While $bytessent < $datasize
$bytessent += TCPSend($socket, StringMid($data, 1 + $bytessent, 1024)) ;1+ :stringmid starts at 1
WEnd

TCPSend($socket, @CRLF)

If $bytessent == 0 Then
Return SetError(2, @error, 0)
EndIf

Return SetError(0, 0, $bytessent)
EndFunc ;==>_HTTPPost

The best would to use winapi functions to read the file at X offset; because you want to send the data of a file, right?

Br, FireFox.

 

Edited by Malharhak
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...