TheDeath24

Read picture and send it per http request

1 post in this topic

Hello,

at first sorry for my bad english. Second i have a Problem.

I want to send a Picture per Http Request with autoit, but allways when i send the Picture with the http request then only comes a hexcode. I  want to habe the binarycode and want to send it as binary.

When i the $sFileRead in a Textfile then it write the binarycode, but when i open a msgbox with $sFileRead in it the code is hex.?!?!?

When you send or run the function then you can go to this page and see what you was send.   http://requestb.in/19g7yg91?inspect

I hope anybody can help me.?

 

 

Func Sendpicture()
$sFilePath = @ScriptDir & "/iphonehdwallpapers_net.jpg"
Local $sFile = FileOpen($sFilePath, 16)
If $sFile = -1 Then
 MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
 EndIf

Local $sFileRead = FileRead($sFile)
MsgBox(0,"Code", $sFileRead)
FileClose($sFile)

;debug info
    If FileExists("output.jpg") Then FileDelete("output.jpg")
    $file = FileOpen("output.jpg", 1)
    FileWrite($file, $sFileRead)
    FileClose($file)

$sBoundary = "------WebKitFormBoundary"&Chr(Random(Asc("A"), Asc("Z"), 3))&Chr(Random(Asc("a"), Asc("z"), 3))&Chr(Random(Asc("A"), Asc("Z"), 3))&Chr(Random(Asc("a"), Asc("z"), 3))&Random(1, 9, 1)&Random(1, 9, 1)&Random(1, 9, 1)

Local $sPD
$sPD = $sBoundary & @CRLF & _
 'Content-Disposition: form-data; name="photo"; filename="Test.jpg"' & @CRLF & _
 'Content-Type: image/jpeg' & @CRLF & @CRLF & _
 $sFileRead

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "http://requestb.in/19g7yg91", False)
$oHTTP.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36")
$oHTTP.SetRequestHeader("Content-Type", 'multipart/form-data; boundary="' & $sBoundary & '"')
$oHTTP.SetRequestHeader("Accept-Encoding", 'gzip, deflate')
$oHTTP.setRequestHeader("Content-Length", StringLen($sPD))
$oHTTP.Send ($sPD)
$oHeaderResponses = $oHTTP.GetAllResponseHeaders()
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status
ConsoleWrite($oStatusCode & @CRLF)
ConsoleWrite($oReceived)
ConsoleWrite($oHeaderResponses)
EndFunc

 

 

Share this post


Link to post
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