cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Curl question (form php and variables)

From: Ray Satiro via curl-users <curl-users_at_cool.haxx.se>
Date: Tue, 1 Nov 2016 02:37:20 -0400

On 10/31/2016 11:51 AM, DannyTheGreat wrote:
> I have a question inherent to Curl command, I'm interested to download
> a file with CURL by batch command, the url of the file is this
> http://www.armaholic.com/page.php?id=30431
> <http://www.armaholic.com/page.php?id=30431>. The file is generated by
> click "submit" form. I have tried more options, and my command is this:
>
>
> curl -v --data-urlencode
> "captcha=I%%20am%%20a%%20human^!&submit=Click%%20to%%20download%%20=BTC=%%20Militia"
> --header "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64;
> x64) AppleWebKit/537.36 (KHTML, like Gecko)
> Chrome/54.0.2840.71 Safari/537.36"
> "http://www.armaholic.com/page.php?id=30431
> <http://www.armaholic.com/page.php?id=30431>" -o
> "BTC-Militia-version-1.1.7z" -L
>
> I have wrote %%20 for space instead %20 because I have seen that the
> batch command don't send correctly %20 but only "0" and the "!" symbol
> if not comprensive of "^!".
>
> The form inside the page is this:
>
> <form method="post"
> action="http://www.armaholic.net/downloader.php?download_file=chili/addons/units/BTC-Militia-version-1.1.7z
> <http://www.armaholic.net/downloader.php?download_file=chili/addons/units/BTC-Militia-version-1.1.7z>"><div
> style="display:inline;margin:0;padding:0"><input type="hidden"
> name="x" value="3910CD8F"></div>
> <div class="hide-s">
> <label for="super">What is two plus two?</label>
> <input name="super" type="text" size="4" id="super"></div>
> <input type="hidden" name="captcha" value="I am a human!">
> <input type="submit" name="submit" value="Click to download =BTC=
> Militia">
> </form>
>
>
>
> I must simply fill the form values, "captcha = I am a human!" and
> "submit = Click to download = BTC = Militia".
>
> What am I doing wrong? Can you help me? My command is for Win Batch
> Command.
>

You are using --url-encode wrong, please review the documentation [1].
Use it once for each name=content, and also use it only when the data
isn't already encoded. (Maybe the docs could be clearer here?)

In a windows batch file if you split that form over multiple lines it
looks like this

curl ^
   --data-urlencode "x=3910CD8F" ^
   --data-urlencode "super=" ^
   --data-urlencode "captcha=I am a human!" ^
   --data-urlencode "submit=Click to download =BTC= Militia" ^
   http://website

The reason %21 in a batch file causes a problem is because windows reads
it as %2 (the second argument passed to the batch file) and then the
number 1. So it would become "I am a human1" assuming there's no second
argument. Tricky. I use percent symbols as little as possible.

There is another problem though which is the website you are trying to
access has some countermeasure to prevent scripted downloads. Your best
bet would be contact the webmaster and ask for permission.

[1]: https://curl.haxx.se/docs/manpage.html#--data-urlencode

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-users
FAQ: https://curl.haxx.se/docs/faq.html
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-11-01