Jump to content

HTTP FORM POST Upload


Tim Net
 Share

Recommended Posts

I've tried several ways of using TCPSend to do a HTTP FORM UPLOAD and have been unsuccessful. Does anyone have a UDF or working example of doing this?

One of the problems is that I am not sure how exactly to calculate the Content-Length.

Thanks in advance.

Tim

Link to comment
Share on other sites

Here i made an example with WinHTTP-UDF: http://www.autoitscript.com/forum/index.ph...st&p=610967

(started with TCPSend, changed to WinHTTP.)

the TCP functions can be found here: http://www.autoit.de/index.php?page=Thread&threadID=6555

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Here's the code of what I think should work:

$line_1 = "POST /Capture/do.asp HTTP/1.1"
$line_2 = "Host: www.domain.com"
$line_3 = "Accept: */*"
$line_4 = "Content-Length: "
$line_5 = "Content-Type: multipart/form-data; boundary=----------------------------ef2347b648ea"
$line_6 = "------------------------------ef2347b648ea"
$line_7 = 'Content-Disposition: form-data; name="stuff"; filename="stuff.txt"'
$line_8 = "Content-Type: text/plain"
$stuff = Fileopen( @ScriptDir & "\stuff.txt", 0)
$data = FileRead($stuff)
$line_9 = "------------------------------ef2347b648ea"

$content_length = stringlen($line_6) + stringlen($line_7) + stringlen($line_8) + stringlen($data); + stringlen($line_9)

$line_4 = $line_4 & $content_length 


TCPStartup()
$connection = TCPConnect("192.122.12.3",80)
tcpsend($connection ,$line_1 & @crlf)
tcpsend($connection ,$line_2 & @crlf)
tcpsend($connection ,$line_3 & @crlf)
tcpsend($connection ,$line_4 & @crlf)
tcpsend($connection ,$line_5 & @crlf)
tcpsend($connection ,@crlf)
tcpsend($connection ,$line_6 & @crlf)
tcpsend($connection ,@crlf)
tcpsend($connection ,$line_7 & @crlf)
tcpsend($connection ,$line_8 & @crlf)
tcpsend($connection ,@crlf )
tcpsend($connection ,$data)
tcpsend($connection ,@crlf)
tcpsend($connection ,$line_9 & @crlf)
tcpsend($connection ,@crlf)
TCPShutdown()
Exit
Link to comment
Share on other sites

Here's the code of what I think should work:

$line_1 = "POST /Capture/do.asp HTTP/1.1"
$line_2 = "Host: www.domain.com"
$line_3 = "Accept: */*"
$line_4 = "Content-Length: "
$line_5 = "Content-Type: multipart/form-data; boundary=----------------------------ef2347b648ea"
$line_6 = "------------------------------ef2347b648ea"
$line_7 = 'Content-Disposition: form-data; name="stuff"; filename="stuff.txt"'
$line_8 = "Content-Type: text/plain"
$stuff = Fileopen( @ScriptDir & "\stuff.txt", 0)
$data = FileRead($stuff)
$line_9 = "------------------------------ef2347b648ea"

$content_length = stringlen($line_6) + stringlen($line_7) + stringlen($line_8) + stringlen($data); + stringlen($line_9)

$line_4 = $line_4 & $content_length 


TCPStartup()
$connection = TCPConnect("192.122.12.3",80)
tcpsend($connection ,$line_1 & @crlf)
tcpsend($connection ,$line_2 & @crlf)
tcpsend($connection ,$line_3 & @crlf)
tcpsend($connection ,$line_4 & @crlf)
tcpsend($connection ,$line_5 & @crlf)
tcpsend($connection ,@crlf)
tcpsend($connection ,$line_6 & @crlf)
tcpsend($connection ,@crlf)
tcpsend($connection ,$line_7 & @crlf)
tcpsend($connection ,$line_8 & @crlf)
tcpsend($connection ,@crlf )
tcpsend($connection ,$data)
tcpsend($connection ,@crlf)
tcpsend($connection ,$line_9 & @crlf)
tcpsend($connection ,@crlf)
TCPShutdown()
Exit
Check sent before TCPShutdown() - you lack time

♡♡♡

.

eMyvnE

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...