I'm trying to use cURL (in a bash script) to load a page on my ISPs site containing my monthly data usage.
Here's the relevent form from the page:
<form method="post" id="Login" name="Login" action="https://signon.bigpond.com/login" class="form">
<input type="hidden" name="goto" value="https://my.bigpond.com/mybigpond/default.do?ref=Net-Header-MyBigPond1"/>
<div class="loginModule roundify">
<div class="loginForm">
<div class="formRow error">
<label for="userName">
Username<span class="reqField">*</span>
</label>
<input type="text" tabindex="1" id="username" name="username" size="30" maxlength="200" onkeypress="EnterKeyPress(event)" value=""/>
</div>
<div class="formRow error">
<label for="password">
Password<span class="reqField">*</span>
</label>
<input type="password" tabindex="2" id="password" name="password" size="30" maxlength="50" onkeypress="EnterKeyPress(event)"/>
</div>
<div class="buttons">
<input class="submit roundify" type="submit" value="Log in" onclick="setCookieForUser();this.disabled=true;document.forms['Login'].submit();" />
</div>
</div>
</div>
</form>
Note that the submit button doesn't have a name.
The function called when text is entered into the form:
function EnterKeyPress(e) {
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
if ( code == 13 && document.getElementById("username").value.length > 0 && document.getElementById("password").value.length > 0 ) {
document.forms['Login'].submit();
e.returnValue = false;
}
}
The cURL command line:
$ curl --user-agent "Mozilla/5.0" --verbose --location --cookie-jar "/tmp/bigpond.cookies" --cookie "/tmp/bigpond.cookies" -o "/tmp/bigpond.html" --data-urlencode "username=MY_USERNAME&password=MY_PASSWORD" https://signon.bigpond.com/login?goto=https://my.bigpond.com/mybigpond/default.do?ref=Net-Header-MyBigPond1
However, the saved html file (/tmp/bigpond.html) is just the logon page still, with text added saying I forgot to enter my username and password. Why is cURL not sending the POST data or what am I doing wrong?
Update: Answered my own question. See below for solution.
Try that :
curl -A "Mozilla/5.0" -b /tmp/c -c /tmp/c -L -s -d "username=<USER NAME>&password=<PASSWORD>" https://signon.bigpond.com/login
And compare the headers of cURL with LiveHttpHeaders firefox module
The problem was passing the POST data to cURL in one argument was causing the data to be mangled when cURL did the URL encoding. The correct usage is to pass each field as a separate argument like so:
curl --data-urlencode "username=XXXXXX" --data-urlencode "password=XXXXXX" ...
Related
I found this question from over a year ago that exactly matches mine, but no answers.
Postman curl:
curl --location --request POST 'http://127.0.0.1:8080/register' \
--header 'Cookie: connect.sid=s%3AZpgwFoDrgb23EX1DPXnehAB4REEoFFRS.s2%2B12XeRx9ugG2E6WtmGbxJmPv9y13unu2EdsUYdS8M' \
--form 'username="bob"' \
--form 'email="bob#bob.com"' \
--form 'password="password"' \
--form 'confirmPassword="password"' \
--form 'image=#"/C:/Users/<me>/Pictures/My Headshot.jpg"'
front-end EJS:
<form action="/register" method="POST" id="register-form" enctype="multipart/form-data">
<div class="input-group mb-3">
<label for="username" class="form-label input-group-text">Username</label>
<input type="text" class="form-control" id="username" placeholder="ILuvBooks101" value="<%= typeof username !== 'undefined' ? username: '' %>">
</div>
<div class="input-group mb-3">
<label for="email" class="form-label input-group-text">Email address</label>
<input type="email" class="form-control" id="email" placeholder="name#example.com" value="<%= typeof emailAddress !== 'undefined' ? emailAddress: '' %>">
</div>
<div class="input-group mb-3">
<label for="password" class="form-label input-group-text">Password</label>
<input type="password" class="form-control" id="password">
</div>
<div class="input-group mb-3">
<label for="confirmPassword" class="form-label input-group-text">Confirm Password</label>
<input type="password" class="form-control" id="confirmPassword">
</div>
<div class="input-group mb-3">
<label for="profilePicture" class="form-label input-group-text">Profile Picture</label>
<input class="form-control" type="file" id="image">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
From Postman, everything works fine, but when testing the actual app's form, I get undefined for req.file and {} for req.body
Any insight would be appreciated!
.......... I forgot to set the name attribute of the fields in the form. Works fine now. It's always the simple things, isn't it?
I try to create a simple contact form, but I didn't get any message, the post request is made. I am pretty new with Modx.
What I tried:
Link 1
Link 2
I created 2 Chunks (emailChunkTpl and MyEmailChunk), and in my template I call for the [[$MyEmailChunk]]. Obviously I did something wrong but I am not sure what. The code is like in the examples, but with some changes,like my email.
[[!FormIt?
&hooks=`email,FormItSaveForm `
&emailTpl=`emailChunkTpl`
&emailTo=`myEmail#gmail.com`
&emailUseFieldForSubject=`1`
]]
<form action="[[~[[*id]]]]" method="post" class="contactForm">
<div class="row input-section-child">
<div class="col input-contact">
<input value="[[!+fi.input-name]]"class="input-name" name="input-name" id="input-name" type="text" placeholder="your name" />
<input value="[[!+fi.input-email]]" class="input-email" name="input-email" id="input-email" type="text" placeholder="email address" />
</div>
<div class="col input-contact-text">
<input value="[[!+fi.input-textare]]"class="input-textare" name="input-textare" id="input-textare" type="textare" placeholder="message" />
</div>
</div>
<div class="row second-row">
<div class="col checkbox">
<input value="[[!+fi.input-checkbox]]" class="input-checkbox" name="input-checkbox" id="input-checkbox" type="checkbox" ><span class="input-checkbox-span">I agree to the Privacy policy.</span>
</div>
<div class="col">
<button type="submit" class="send-button">SEND</button>
</div>
</div>
<a href="#intro" class="back-to-top"><img src="images\arrow-back.svg" /><span>Back to top</span>
</div>
</from>
You should start with cleaning up your markup, it is not valid HTML. There is a typo in your closing form tag (/from), an extra closing div tag, there is no input type of textare as far as I know, and you are missing white space around some classes. You can validate HTML here: https://validator.w3.org/
You can test to make sure your site is setup properly to send an email. There is a snippet for this called QuickEmail, download it from the extras tab in the MODX manager.
Once you're sure your site can send email, then start with a stripped down version of the Formit call -- remove all hooks except email and get it working with that first. Then add hooks one at a time.
In my ZnClient request I get a response from the server which is a HTML format containing key and value that I would like to extract and store for later use. How do I do it in Pharo?
<div id="login_block">
<div class="text-center"><img src="/static/img/logo-mool2016.black.7272bc78ba54.png" width="223" alt=LOGO" onclick="showChooseLogin();"></div>
<h3 class="text-center">Connectez-vous pour accéder à <span class="product-name">Tool Platform</span></h3>
<div id="login_choosen" class="login_block ui-widget-content ui-corner-all">
<form method="post" action="." id="login_form"><input type='hidden' name='csrfmiddlewaretoken' value='fLTzkLA7yhy7YKDvohM0PJstFJJCEk2JinfjOyzCe2NA495QKznLgO1wzi64P2S8' />
<p><label for="id_email">Email :</label> <input class="login" id="id_email" maxlength="75" name="email" type="text" required /></p>
<p><label for="id_password">Password :</label> <input class="login" id="id_password" name="password" type="password" required /></p>
<button type="submit" class="btn btn-connect pull-right">Connexion</button>
</form>
</div>
</div>
You can extract this information using a HTML parser like Soup.
Here's a cut-down working example:
|content soup dict|
content := '
<div>
<form method="post" action="." id="login_form">
<input type="hidden" name="csrfmiddlewaretoken" value="***special***" />
<input class="login" id="id_email" name="email" type="text" required />
</form>
</div>'.
dict := Dictionary new.
soup := Soup fromString: content.
(soup findAllTags: 'input') do: [ :each |
dict at: (each attributeAt: 'name') put: (each attributeAt: 'value') ].
dict now contains the following:
'csrfmiddlewaretoken'->'***special***'
'email'->nil
You can load XMLParserHTML and XPath from the Pharo Catalog. Then this should do the trick:
| xPath htmlDoc inputs input |
"match inputs with token value of the name attrite"
xPath := '//input[#name="csrfmiddlewaretoken"]' asXPath.
"parse your html"
htmlDoc := (XMLHTMLParser on: htmlString) parseDocument.
"match all inputs with the token"
inputs := xPath in: htmlDoc.
"assuming there is only 1 element like that"
input := inputs first.
"get the value attribute from the element"
^ input attributeAt: 'value'.
How do I trigger a get request from a bootstrap button? I have the following code:
<form class="navbar-form navbar-right" role="form">
<div class="form-group">
<input type="text" placeholder="Email" class="form-control">
</div>
<div class="form-group">
<input type="password" placeholder="Password" class="form-control">
</div>
<button type="submit" class="btn btn-success">Sign in</button>
<button type="submit" class="btn btn-warning" value="/signup" id="submit">Sign up</button>
</form>
and would like this button to perform a get request with the following value "signup"
I am using a MEAN stack and the routes are set up so when the app is accessed with the get value /signup it goes to the signup page. But I am not able to get the bootstrap 3 button to post a get a request.
On your form you will need the following two attributes:
Action = "{URL TO SEND THE FORM TO}"
Method = "{GET or POST}"
For a signup with a username and password you should really think about doing a POST request so the form element should look like (for a POST request):
<form action="/signup" method="POST" class="navbar-form navbar-right" role="form">
or for a get request:
<form action="/signup" method="GET" class="navbar-form navbar-right" role="form">
Trying to send user feedback to email using an embedded contact form; without using a mailto:
I have a mostly static web page served up by nginx containing html/browser-javascript.
The strategy is very similar to this:
http://www.phpeasystep.com/phptu/8.html
My static page has a form section:
<form action="sendmail.js" method="post" id="contactForm">
<div class="sep">
<label for="name" class="txt">Name:</label>
<input type="text" name="name" value="" id="name">
</div>
<div class="sep">
<label for="email" class="txt">Email:</label>
<input type="text" name="email" value="" id="email">
</div>
<div class="sep">
<label for="tele" class="txt">Telephone:</label>
<input type="text" name="tele" value="" id="tele">
</div>
<div class="sep special">
<label for="last" class="txt">Don't fill this in:</label>
<input type="text" name="last" value="" id="last">
</div>
<div class="sep">
<label for="message" class="txt">Message:</label>
<textarea rows="5" name="message" id="message"></textarea>
</div>
<div class="buttonAlign submitbutton">
<button type="submit" class="button mediumButton" id="submit">Send Message</button>
</div>
</form>
I want the form elements passed to a server side node.js script, sendmail.js, and have that script compose an email with the form elements then dispatch.
I'm rather new to node.js and nginx and I'm not sure what I'm missing; but, its not working, the script is not running at all.
I've added nothing special to the nginx default.conf file.
The node.js script is in my base directory and if I rename it, I get a file not found error. So, I know nginx is looking for it. The first line of the script file has the node.js she-bang and its chmod'ed to executable.
Appreciate any help.
I get the following message in access.log
==> access.log <==
"POST /sendmail.js HTTP/1.1" 405 574 "https://xyzzy.net/index.html" "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)" "-"
I'm not expecting a response to appear in the web page. I just want to execute the sendmail.js script and send an email containing the form data.
Here's a 'dummy' script which attempts to create/write a 'breadcrumbs' file in /tmp
#!/usr/local/bin/node
var fs = require('fs');
fs.writeFile("/tmp/test", "Hey there!", function(err) {
if(err) {
console.log(err);
} else {
console.log("The file was saved!");
}
});