AutoHotkey Community

It is currently May 25th, 2012, 4:08 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: May 7th, 2007, 12:42 pm 
Offline

Joined: November 27th, 2006, 7:41 am
Posts: 222
Location: Queensland, Australia
I'm using cURL as part of an AHK script to FORM submit "multipart/form-data".
Everything works fine except where I have newline (`n) in the forms 'comment' field (so the user can type in comments etc to go with the upload) , but this stops cURL from submitting the data.
I have tried stringreplace `n with things like %0D%0A, but it just comes through literally and not as a newline.

I assume the problem lies in AHK interpreting the `n as a break in what is otherwise a single continuous line of text. cURL seems to convert everything it receives perfectly, so i must be missing some formatting/stringreplace/conversion in AHK before i feed cURL the command string.

What am i forgetting to do?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 7th, 2007, 1:11 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Not sure, but IIRC:
1) Mime uses CR+LF as line break, so you can try and replace the `n with `r`n sequence;
2) its escape sequence is =HH, eg. =3D for the equal sign, =A0 for the euro sign in ISO-8859-1, and so on. So perhaps =0A can be used for a line break, if the first solution doesn't work.

[EDIT] I gave =10 for newline, ie. the decimal value instead of the hexa one. Doh!

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Last edited by PhiLho on May 7th, 2007, 5:34 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 7th, 2007, 1:58 pm 
Offline

Joined: November 27th, 2006, 7:41 am
Posts: 222
Location: Queensland, Australia
hmmm...
http://www.bbsinc.com/iso8859.html
line feed, new line LF, NL ^J 0A
...

lets say i enter this:
Quote:
...
....

the newline is actually an `n (i checked)

if i do this:
Code:
StringReplace, ROWCOMMENTVALUE, ROWCOMMENTVALUE, `n,=10, A
result

I get this: (as you would expect)
Code:
ROWCOMMENTVALUE=...=10...

COMMANDLINE=curl.exe http://***.org/s/imgboard.php -F "com=...=10..." -F "upfile=@x:\0012.jpg"....etc


...and of course if i stringreplace `n with `r`n it just munches the COMMANDLINE with a carriage return in the middle of it.

If I convert the `n to a %0D%0A or =10 etc it just goes through cURL literally, so evidently I need to use something that cURL will translate correctly, but will not prematurely terminate/linefeed the command line in AHK that i am feeding to cURL.

I'm tired, so this is probably something really simple.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 7th, 2007, 2:43 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Maybe you have to specify data transfer mode?

--use-ascii

or

--data
--data-ascii
--data-binary


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 7th, 2007, 5:36 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Two other ideas:
1) Try \n, perhaps cURL can intepret it.
2) Put the comment in a file, and load it with @

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 8th, 2007, 12:02 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
If you're going to use PhiLho's second suggestion, you may consider to use StdIn method:
http://www.autohotkey.com/forum/viewtopic.php?t=16823

Code:
sCmd := "curl.exe"
sInput := "your_data"

CreatePipe(hStdInRd , hStdInWr ) ; Create a pipe for StdIn
SetHandleInformation(hStdInRd ) ; make the handle hStdInRd inheritable to a child process, the console app
CreateProcess(sCmd) ; Create the console app without creating a console window
StdInput( sInput , hStdInRd , hStdInWr ) ; complete the StdIn


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 8th, 2007, 4:08 am 
Offline

Joined: November 27th, 2006, 7:41 am
Posts: 222
Location: Queensland, Australia
Sean wrote:
Maybe you have to specify data transfer mode?

If I'm not mistaken this would effect the file transfer, and not the input of form <input> fields... But I'll put that at the bottom of the list of things to try.

Sean wrote:
If you're going to use PhiLho's second suggestion, you may consider to use StdIn method:
http://www.autohotkey.com/forum/viewtopic.php?t=16823

A quick read of that gives me the feeling that it's a bit more involved/complex than I need. So I'll try that later too.
I've marked it as "probably going to be useful for something else later" though, it looks very useful.

PhiLho wrote:
2) Put the comment in a file, and load it with @

Yes, this occurred to me last night as I was trying to get to sleep; but not the way you say above: but rather that it would be a simple matter to use the same method I have been using to insert another field using a pipe:
ie:
Code:
COMMANDLINE = curl.exe %SELECTEDBOARDurl% -F "resto=<postto.txt" -F "name=%NAME%" -F "email=%ROWEMAILVALUE%" -F "pwd=%PASSWORD%"  -F "sub=%ROWSUBJECTVALUE%" -F "com=%ROWCOMMENTVALUE%" -F "upfile=@%ROWFILENAMEVALUE%" -F "submit=Submit" -F "mode=regist" -A "%AGENT%" --progress-bar --stderr %A_ScriptDir%\%PROGRESSFILE% -D %A_ScriptDir%\%HEADERS%>%A_ScriptDir%\%RESPONSE%


So I will try substituting this <filename.ext method to pipe in the comments as well. I'm fairly sure that will work.

[edit] Update: yep, worked perfectly. As a bonus; very few code additions/changes were required.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: dra, poserpro, rjgatito, Yahoo [Bot] and 22 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group