Jump to content

Works as .au3 but breaks after Aut2Exe compiles it, can't figure it out!


Recommended Posts

Hello, I hope you could help me out on this issue as it's kind of out of my reach. I have made a POST/GET client to POST a file to a server and later get a updated version and store it. Now the download aspect works fine and saves it just right, but the issue is the POST.

First I will declare the important functions I use to achieve my POST:

I create a ObjCreate() where it tries to create a object of Msxml2.XMLHTTP.6.0, Msxml2.XMLHTTP.3.0, Msxml2.XMLHTTP or Microsoft.XMLHTTP. If all fail then the upload fails otherwise it uses the first available.

Then I create a $boundary "---------- boundary<random digits, 9 in lenght>_<random digits, 9 in lenght>_<random digits, 4 in lenght>"

After that I simply construct the body of the POST, here is the code:

$opt[8] = "UTF-8", $filename = "Test.lua", _LoadFile($file) returns properly UTF-8 encoded plain text (FileOpen($file, 128)).

$body &= "--" & $boundary & @CRLF
$body &= "Content-Disposition: form-data; name=""lua""" & @CRLF
$body &= @CRLF
$body &= $filename & @CRLF
$body &= "--" & $boundary & @CRLF
$body &= "Content-Disposition: form-data; name=""lua""; filename=""" & $filename & """" & @CRLF
$body &= "Content-Type: application/octet-stream; charset=" & $opt[8] & @CRLF
$body &= "Content-Transfer-Encoding: binary" & @CRLF
$body &= @CRLF
$body &= _LoadFile($file) & @CRLF
$body &= "--" & $boundary & "--" & @CRLF

$oHttp.Open("POST", $url, False)
$oHttp.setRequestHeader("Content-Type", "multipart/form-data; charset=" & $opt[8] & "; boundary=" & $boundary)
$oHttp.setRequestHeader("Content-Length", StringLen($body))
$oHttp.Send($body)

I get the response using $oHttp.responseText and this all works really well, no problems at all... until:

I use Aut2Exe on my .au3 (working without problems) script and generate a executable. Now just notice that I use Win7 and I must save it as anything else but a ".exe" otherwise the UPX fails (permission issues) but it's not a problem as I after just rename .txt to .exe and it works, at least all my other application compilations like this work just fine.

Anyway once I do this the server rejects the POST I guess, what could it be? I doubt it's server issue as it works both the normal method (going on the website and manually using the upload form) and it works when the file is a raw .au3!

I hope someone could help me out here, I assume I either use the wrong method as in I should perhaps load the file "wrongly" formatted or as pure ASCII and get messed up code + declare charset as UTF-8 or maybe remove charset and do something with the body itself, the encoding of the plain text I try to upload as a file, anyway thanks for your time reading but I need some help -tried a lot of things but nothing helped. ;)

I am using the latest AutoIT3 beta, Win7 EN, 32bit with 64bit hardware (if that matters).

Link to comment
Share on other sites

This is going to be annoying, but you need to trim out areas and compile and test and see if it will run without an error

OR

put some message boxes in to see which ones populate before the error, so you can narrow it down to where the general few lines of code are

Make sense?

Hello, I hope you could help me out on this issue as it's kind of out of my reach. I have made a POST/GET client to POST a file to a server and later get a updated version and store it. Now the download aspect works fine and saves it just right, but the issue is the POST.

First I will declare the important functions I use to achieve my POST:

I create a ObjCreate() where it tries to create a object of Msxml2.XMLHTTP.6.0, Msxml2.XMLHTTP.3.0, Msxml2.XMLHTTP or Microsoft.XMLHTTP. If all fail then the upload fails otherwise it uses the first available.

Then I create a $boundary "---------- boundary<random digits, 9 in lenght>_<random digits, 9 in lenght>_<random digits, 4 in lenght>"

After that I simply construct the body of the POST, here is the code:

$opt[8] = "UTF-8", $filename = "Test.lua", _LoadFile($file) returns properly UTF-8 encoded plain text (FileOpen($file, 128)).

$body &= "--" & $boundary & @CRLF
$body &= "Content-Disposition: form-data; name=""lua""" & @CRLF
$body &= @CRLF
$body &= $filename & @CRLF
$body &= "--" & $boundary & @CRLF
$body &= "Content-Disposition: form-data; name=""lua""; filename=""" & $filename & """" & @CRLF
$body &= "Content-Type: application/octet-stream; charset=" & $opt[8] & @CRLF
$body &= "Content-Transfer-Encoding: binary" & @CRLF
$body &= @CRLF
$body &= _LoadFile($file) & @CRLF
$body &= "--" & $boundary & "--" & @CRLF

$oHttp.Open("POST", $url, False)
$oHttp.setRequestHeader("Content-Type", "multipart/form-data; charset=" & $opt[8] & "; boundary=" & $boundary)
$oHttp.setRequestHeader("Content-Length", StringLen($body))
$oHttp.Send($body)

I get the response using $oHttp.responseText and this all works really well, no problems at all... until:

I use Aut2Exe on my .au3 (working without problems) script and generate a executable. Now just notice that I use Win7 and I must save it as anything else but a ".exe" otherwise the UPX fails (permission issues) but it's not a problem as I after just rename .txt to .exe and it works, at least all my other application compilations like this work just fine.

Anyway once I do this the server rejects the POST I guess, what could it be? I doubt it's server issue as it works both the normal method (going on the website and manually using the upload form) and it works when the file is a raw .au3!

I hope someone could help me out here, I assume I either use the wrong method as in I should perhaps load the file "wrongly" formatted or as pure ASCII and get messed up code + declare charset as UTF-8 or maybe remove charset and do something with the body itself, the encoding of the plain text I try to upload as a file, anyway thanks for your time reading but I need some help -tried a lot of things but nothing helped. ;)

I am using the latest AutoIT3 beta, Win7 EN, 32bit with 64bit hardware (if that matters).

Link to comment
Share on other sites

Thanks for the tips guys, but oddly enough the code as-is worked fine when I compiled using latest Beta build (I otherwise used latest regular build). Did not change the code, both au3 and compiled exe were in the same folder at testing and it worked with the beta compiler. Really odd, guess a undocumented fix for Win7 perhaps. Anyway glad it works now, hehe. :D

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