Jump to content

HTTPS Post and Request


Recommended Posts

A little help here please !?

I'm trying to parse a file but the function is not working well! i think there is some thind doing wrong at FileRead()

Obs: username,password and API link below is fictitious

ConsoleWrite(">POST METHOD UPLOADING LOCAL IMAGE<" & @CRLF)
_PostMethodTest()


Func _PostMethodTest()
    Local Const $sAPIKey = '8f1e0a750088957'
    Local $sBoundary = "--------Boundary"
    Local $sHeaders = "Content-Type: multipart/form-data; boundary=" & $sBoundary & @CRLF
    Local $sData = ''
    Local $sFileName="image.jpg"
    Local $sFilePath="C:\Users\DELL\Desktop\" & $sFileName
    Local $hFile=FileOpen($sFilePath,16);16=$FO_BINARY
    Local $sFileData=FileRead($hFile)
    FileClose($hFile)

    $sData &= "--" & $sBoundary & @CRLF
    $sData &= 'Content-Disposition: form-data; name="myImage"; filename="' & $sFileName  & '"' & @CRLF
    $sData &= 'Content-Type: application/upload' & @CRLF & @CRLF
    $sData &= BinaryToString($sFileData,0) &  @CRLF
    $sData &= "--" & $sBoundary &  @CRLF
    $sData &= 'Content-Disposition: form-data; name="username"' & @CRLF & @CRLF
    $sData &="myuserName" & @CRLF
    $sData &= "--" & $sBoundary &  @CRLF
    $sData &= 'Content-Disposition: form-data; name="password"' & @CRLF & @CRLF
    $sData &="MyPassword" & @CRLF
    $sData &=$sBoundary & "--"

    ConsoleWrite($sData)
    
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("POST", "http://myapi", False)
    $oHTTP.SetRequestHeader("Content-Type", "multipart/form-data; " & "boundary=" & $sBoundary)
    $oHTTP.SetRequestHeader("apikey", $sAPIKey)
    $oHTTP.Send(StringToBinary($sData,1))
    Local $sReceived = $oHTTP.ResponseText
    ConsoleWrite($sReceived & @CRLF)

EndFunc   ;==>_PostMethodTest

 

Capturar.PNG

Link to comment
Share on other sites

  • Moderators

To the person who reported this thread, you have been asked more than once to STOP reporting threads with no context. The forum rules state very plainly that when reporting you need to enter details about why you believe it is breaking those rules. 

@Melque_Lima I expect you understand that, if this thread turns out to be you attempting the same thing as your previous post, your time on our forum will be short-lived, yes? :)

 

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • 2 weeks later...

You can't mix binary data in a string variable. The contrary (inserting string in binary data) is, however, OK to do.

In your case, the problem is that you start a string variable and then insert binary data, converted to string. It should be the contrary: you should convert the strings to binary, and not the binary to string.

If you look at my signature, you'll find "HTTP.au3". On that UDF, there is a _HTTP_Upload() function that you may use or take as reference. It also makes use of WinHTTP.

My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS ·  storage.au3 localStorage and sessionStorage for AutoIt Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path GUICtrlStaticMarquee static text scrolling Random stuff Super Mario beep sound your ears will hurt

 

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

×
×
  • Create New...