Can I fill and submit this form with cURL?

0

I am trying to submit data to a form at work. I suspect that my naive approach doesn't work because of "technology" in the page that interferes with it. Basically, the webpage (sorry I cannot link to it here, it is not public) has

<form action="login.php" method="get" name="LogIn" class="form-signin"> 

and then several inputs like

<input type="text" class="form-control" id="docIdent" name="docIdent" placeholder="@" required>

so I am trying the following cURL command:

curl -d "docIdent=WHATEVER" -d "type=WHATEVER" -d "comment=" URL

where the three pieces of data seem to be needed were obtained by: 1. Downloading the .html. 2. Changing the form method from "post" to "get" and opening it in a browser. 3. Filling the form and submitting (got a "page not found" error, of course, but the new URL had all that data, including the empty 3rd field).

Well, it doesn't work (I get back the same login page, and I can check that there has been no login at the time I try). I don't know much about these things but I suspect it can be some other code not in the page: there is

<script src="dist/js/bootstrap.min.js"></script>
<script src="dist/js/jquery-3.4.1.min.js"></script>
<script src='js/fns.js'></script>

and of course the "login.php" in the form opening. From many other posts, my syntax seems correct; is there any hope for an automatic login (the type of bash script that I will put in cron, like the one-liner I am trying)? Thanks.

David Sevilla

Posted 2019-09-19T10:16:48.283

Reputation: 1

Can you check the actual form submit data using your browser's DevTools, this time without changing the form method or the page's origin in any way? – user1686 – 2019-09-19T10:20:19.190

I'm not sure I'm doing it right, but I found a "Request body" area where I see Content-Type: application/x-www-form-urlencoded Content-Length: 49 docIdent=WHATEVER&type=WHATEVER&comment=. Could that encoding be a clue? – David Sevilla – 2019-09-19T10:34:45.580

Can you also use curl -v ... to check at what is being sent in the second case and compare with the browser? Note that the "type" is not a form field; it is an HTTP header. – user1686 – 2019-09-19T11:39:36.950

Ok, so I tried -v and got among other things: `> User-Agent: curl/7.64.0

Accept: / Content-Length: 49 Content-Type: application/x-www-form-urlencoded

  • upload completely sent off: 49 out of 49 bytes

` which to me means that with cURL I am sending the same as with Firefox... – David Sevilla – 2019-09-19T11:40:18.010

My last attempt has been curl -F "type=application/x-www-form-urlencoded" -F "docIdent=WHATEVER" -F "type=WHATEVER" -F "comment=" URL, not good; also tried changing all the -F to -d, same thing. All I get back is the login page, and I can see in some other way that I didn't make the login. – David Sevilla – 2019-09-24T14:26:27.670

Answers

0

Well, in the end I found the following solution: with my browser (Firefox, Web Developer Tools) I captured the request. It looked like this:

curl 'URL' -H 'Host: SOMETHING' -H 'User-Agent: SOMETHING' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Language: en,en-US;q=0.5' --compressed -H 'Referer: SOMETHING' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1' --data 'WHATEVER'

... plus cookie information, that I removed because I wanted to see if the rest, which does not change every time, was enough. And it worked. Thanks a lot to grawity for the helpful support.

David Sevilla

Posted 2019-09-19T10:16:48.283

Reputation: 1