 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
BETLOG
Joined: 27 Nov 2006 Posts: 218 Location: Queensland, Australia
|
Posted: Mon May 07, 2007 12:42 pm Post subject: how: properly format `n for feeding to cURL? |
|
|
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? |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Mon May 07, 2007 1:11 pm Post subject: |
|
|
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! _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Last edited by PhiLho on Mon May 07, 2007 5:34 pm; edited 1 time in total |
|
| Back to top |
|
 |
BETLOG
Joined: 27 Nov 2006 Posts: 218 Location: Queensland, Australia
|
Posted: Mon May 07, 2007 1:58 pm Post subject: |
|
|
hmmm...
http://www.bbsinc.com/iso8859.html
line feed, new line LF, NL ^J 0A
...
lets say i enter this:
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. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1323
|
Posted: Mon May 07, 2007 2:43 pm Post subject: |
|
|
Maybe you have to specify data transfer mode?
--use-ascii
or
--data
--data-ascii
--data-binary |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Mon May 07, 2007 5:36 pm Post subject: |
|
|
Two other ideas:
1) Try \n, perhaps cURL can intepret it.
2) Put the comment in a file, and load it with @ _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1323
|
Posted: Tue May 08, 2007 12:02 am Post subject: |
|
|
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
|
|
|
| Back to top |
|
 |
BETLOG
Joined: 27 Nov 2006 Posts: 218 Location: Queensland, Australia
|
Posted: Tue May 08, 2007 4:08 am Post subject: |
|
|
| 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.
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. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|