Jump to content

winHTTP Upload Binary Data


Recommended Posts

Welcome to the forum.

My crystal ball is cloudy.

Please post your code or a reproducer of your problem so we may assist you. We cannot help you without that.

Cheers

Link to comment
Share on other sites

are you making sure to url encode the data before transmitting it?

if so you may want to try converting it to hex before uploading so that everything in the data is then represented by a number,then using php to turn it back into binary on the server side.

BTW, fileread is not skipping anything thats simply not possible, the issue is in your handling of the data.

hope this helps

[center][/center][center]=][u][/u][/center][center][/center]

Link to comment
Share on other sites

Hello

Thanks for all replies.

@IchBistTod, I'm not clear about how to convert it to hex before uploading so that everything in the data is then represented by a number,then using php to turn it back into binary on the server side. When I use FileRead, it's something like 0x332330x343333 ... For PHP, I find only number conversion functions like bin2hex, hexdec not data format conversion.

Here's my code:

#include "WinHTTP.au3"

#include <IE.au3> 


$LocalIP = "localhost"
$PostURL = "/upload_php.php"
$hw_open = _WinHttpOpen()

$hw_connect = _WinHttpConnect($hw_open, $LocalIP)

$h_openRequest = _WinHttpOpenRequest($hw_connect, "POST", $PostURL)
$upfile = "test.jpg";
$upsize = FileGetSize($upfile)

$file = FileOpen($upfile , 16)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
$line = ""

While 1
    $line &= FileReadLine($file) 
    If @error = -1 Then ExitLoop
Wend

FileClose($file)

$upcontent = $line

$data = "-----------------------------41184676334" & @CRLF &  'Content-Disposition: form-data; name="userfile"; filename="' & $upfile & '"' & @CRLF &   'Content-Type: application/octet-stream' & @CRLF & @CRLF &  $upcontent & @CRLF & '-----------------------------41184676334--' & @CRLF 

_WinHttpAddRequestHeaders($h_openRequest,"Content-Type: multipart/form-data; boundary=---------------------------41184676334")

_WinHttpSendRequest($h_openRequest,$WINHTTP_NO_ADDITIONAL_HEADERS, $WINHTTP_NO_REQUEST_DATA, StringLen($data), 0)

_WinHttpWriteData($h_openRequest, $data)

_WinHttpReceiveResponse($h_openRequest)

$oIE=_IECreate ()
_IEDocWriteHTML ( $oIE, _WinHttpReadData($h_openRequest))


_WinHttpCloseHandle($h_openRequest)

_WinHttpCloseHandle($hw_connect)

_WinHttpCloseHandle($hw_open)
Edited by autoituser123
Link to comment
Share on other sites

Try this: http://www.autoitscript.com/forum/index.php?showtopic=84133&view=findpost&p=610967

*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

Oops, replace

Local $szExt = StringLower(StringRegExpReplace(,".*(?:\.([^.\\/]*))?\Z","$1"))

with

Local $szExt = StringLower(StringRegExpReplace( $path ,".*(?:\.([^.\\/]*))?\Z","$1"))

*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

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