How to Log In to Website using WebRequest - html

I am trying to make a program log into a website using WebRequest and then copy the html page that comes after login into a string.
let returnHTML (url : string) =
let request = System.Net.WebRequest.Create(System.Uri(url))
let response = request.GetResponse()
let stream = response.GetResponseStream()
let reader = new System.IO.StreamReader(stream)
let webstring = reader.ReadToEnd ()
webstring
printfn "%A" (returnHTML "myURL")
The above code copies the login page into a string because i have not implemented some sort of login session yet. This is where i hope some of you can break it down for dummies.
The form that needs login into looks like this :
<form name="loginform" id="loginform" action="https://aamanasdasdad" method="post">
<p>
<label for="user_login">Brugernavn eller e-mailadresse<br />
<input type="text" name="log" id="user_login" class="input" value="" size="20" /></label>
</p>
<p>
<label for="user_pass">Password<br />
<input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
</p>
<p class="forgetmenot"><label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever" /> Husk mig</label></p>
<p class="submit">
<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Log ind" />
<input type="hidden" name="redirect_to" value="https://aamansasns.asdasddk/wp-admin/admiadasdad" />
<input type="hidden" name="testcookie" value="1" />
</p>
Can someone please guide me on how to reach the last step?

Related

Html Form not submitting data to server

I'm trying to submit Customer data to the server for processing. I'm using an HTML form. But every time I press submit the server doesn't receive any data in the request.
<form data-customer-information-form="true" autocomplete="on" method="POST" action="addticket/submit" name="ticketForm" id="ticketform" accept-charset="UTF-8">
<p>
<label for="customerFirstName">First Name:</label></br>
<input type="text" name="customerFirstName" id="customerFirstName" placeholder="first name" pattern="[A-Za-z]+" tabindex="0">
</p>
<p>
<label for="customerLastName">Last Name:</label></br>
<input type="text" name="customerLastName" id="customerLastName" placeholder="last name" tabindex="0">
</p>
<p>
<label for="phoneNumber">Phone:</label></br>
<input type="tel" id="phone" maxlength="12" name="phoneNumber" placeholder="phone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" tabindex="0">
</p>
<p>
<label for="email">Email:</label></br>
<input type="email" name="email" id="email" placeholder="email">
</p>
<p>
<label for="service">Computer/Service Name:</label></br>
<input type="text" name="service" placeholder="computer model or service">
</p>
<p>
<label for="description">Anything else we need to know:</label></br>
<textarea type="text" maxlength="200" name="description" id="description" placeholder="What's gone wrong?"></textarea>
</p>
<input type="submit" name="submit" value="Submit" id="submit">
</form>
const router = require('express').Router();
const fs = require('fs');
var path = require('path');
const customer = require("../models/customer");
router.get('/', function(req, res) {
req.session.cookie
res.sendFile(path.join(__dirname + "/pages/ticket.html"));
});
router.post('/submit', (req, res) => {
console.log(req.body)
})
module.exports = router;
The request headers all look good telling the server that is a form. But it doesn't have the data. req.body is undefined basically.
Express.js will only populate the body property of a request object if suitable body parsing middleware is used. You aren't using any.
By default, a form will encode form data in the URL encoded format, so you should use that middleware.
const express = require('express');
router.use(express.urlencoded())

How to send an html form with values filled

Basically i have a html form as string
<form class="form login_form" action="https://app.box.com/api/oauth2/authorize?response_type=code&redirect_uri=http://localhost:8080/&client_id=6n8aeye40bowhwz&state=V8eTbbtXbsV" method="post" name="login_form">
<ul class="container error_container basic_list basic_list_sm hidden"><li class="data plm warning ram pas man"><div class="media pvs"><div class="img icon"><div class="sprite_signup_login_icon_error"></div></div><div class="bd"></div></div></li></ul>
<div class="field_set login_fields fw center">
<div class="login_user_inputs"><label for="login" class="field_label user_login_field">Email Address</label><div class="user_login_field text_input_with_sprite text_input_with_sprite_16x16 mbm"><input id="login" class="text_input login_email ram field_element " name="login" type="email" title="Email Address" placeholder="Email Address" value="email#gmail.com"> <label class="icon" for="login" title="Email Address"></label></div><label for="password" class="field_label user_password_field">Password</label><div class="user_password_field text_input_with_sprite text_input_with_sprite_16x16 mbm"> <input id="password" class="text_input login_password ram field_element" name="password" title="Password" placeholder="Password" type="password" autocapitalize="off" autocomplete="off" autocorrect="off" value="passwordstring"> <label class="icon" for="password" title="Password"></label></div> </div> <div class="login_submit_div"><input class="btn btn-primary mhn login_submit fw pvm ram" title="Authorize" value="Authorize" type="submit" name="login_submit"></div> <input type="hidden" name="dologin" value="1" /> <input type="hidden" name="client_id" value="99hxwc5z7wz" /><input type="hidden" name="response_type" value="code" /><input type="hidden" name="redirect_uri" value="http://localhost:8080/" /><input type="hidden" name="scope" value="root_readwrite manage_groups manage_enterprise_properties manage_app_users manage_managed_users" /><input type="hidden" name="folder_id" value="" /><input type="hidden" name="file_id" value="" /> <input type="hidden" name="state" value="Licg8fhDiFyobsV" /> <input type="hidden" name="reg_step" value="" /><input type="hidden" name="submit1" value="1" /><input type="hidden" name="folder" value="" /><input type="hidden" name="login_or_register_mode" value="login" /><input type="hidden" name="new_login_or_register_mode" value="" /><input type="hidden" name="__login" value="1"><input type="hidden" name="redirect_url" value="/api/oauth2/authorize?response_type=code&redirect_uri=http://localhost:8080/&client_id=99hxwc5z7p9g3z&state=LichV8eTbbtXbsV"><input type="hidden" name="request_token" value="5d6b31164f15f58bebff206db0aa595eaa90f5f9b857860f8ac3e64c85a5b5f4"> <input type="hidden" id="_pw_sql" name="_pw_sql" value=""/>
</div>
<div class="sso_switch option_sso mts pvs phm hidden">
Use Single Sign On (SSO)
Use Box account credentials
</div>
</form>
and now i want to submit this form to the url specified in action parameter of form tag. Same as it will be submitted from a browser. And condition is i should not use beego webserver for this.
Thanks in advance
If I understand you correctly, you have to work with an HTML form as opposed to just the input values, and you want to send the input contained in that form to some other server for processing, and you also want to do this programmatically with Go as opposed to clicking on a button inside a browser.
If I got that right, what you have to do is first get the input values, action url, and method from the form. You can do that by using golang.org/x/net/html for example.
After you have all the necessary values you'll have to encode the input values into a valid application/x-www-form-urlencoded string which you can do using the net/url package.
Then all you have to do is to create an http request with http.NewRequest using the form method and action url as it's first two arguments and the urlencoded string as it's last body argument. (You can use strings.NewReader to turn a string into an io.Reader.)
Finally call http.Client.Do on the http.DefaultClient with the newly created request as it's argument.
It's possible that there are some 3rd party packages that do most of this work for you, so if you want to avoid doing this yourself try searching through github.

I need code to send mail fom my Contact Us page

I have designed a contact form and I need to receive mail from the "Contact Us" page, on a specific email ID.
This my form:
contact.html
<form action="contactservlet" method="post">
<h4>Get in <i>Touch</i></h4>
<input type="text" id="name" name="name" placeholder="NAME" class="input-style" />
<input type="email" id="emailid" name="emailid" placeholder="EMAIl" oninput="sendRequest('GET','Checkemailid',1)" required="required" class="input-style" />
<input type="text" id="mobno" name="mobno" placeholder="Enter Mobile No." required="required" class="input-style"/>
<textarea type="text" id="message" name="message" placeholder="MESSAGE" required="required" class="input-style"></textarea>
<div class="contact-btn">
<a title="" href="#"><input type="submit" id="submit" value="Submit"/></a>
</div>
</form>
I don't know how to write contactservlet.java.
UPDATED
Try this,
ContactUs.html
<form action="ContactServlet" method="post">
<h4>Get in <i>Touch</i></h4>
<input type="text" id="name" name="name" placeholder="Name" />
<input type="email" id="emailId" name="emailId" placeholder="Email" />
<input type="text" id="mobileNo" name="mobileNo" placeholder="Enter Mobile No." />
<textarea type="text" id="message" name="message" placeholder="Message"></textarea>
<input type="submit" id="submit" value="Submit"/>
</form>
For sending mails we used JavaMail API. Download and Documentation.
ContactServlet.java -> doPost()
//This data will be added to your Database using DAO Layer....
String name=request.getParameter("name");
String emailId=request.getParameter("emailId");
Long mobno=Long.parseLong(request.getParameter("mobileNo"));
String message= request.getParameter("message");
//Call Some function that do database storage.....
//Sending Mail Through Gmail SMTP
//Separate this code at DAO/Service Layer - - -
final String gmailUsername = "somethin#gmail.com";
final String gmailPassword = "somethin#123";
try{
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
#Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(gmailUsername, gmailPassword);
}
});
Message mailMessage = new MimeMessage(session);
mailMessage.setFrom(new InternetAddress("somethin#gmail.com"));
mailMessage.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(emailId));
mailMessage.setSubject("Type Subject : ");
mailMessage.setText("Type LONGGGG Message Here......");
Transport.send(mailMessage);
} catch(MessagingException e){
e.printStackTrace();
}

Formatting output from mailto:

I'm making a form which collect some data from a person and then use a simple mailto: to put it in their e-mail client like so (example):
<form method="post" action="mailto:email#address.com?subject=Stuff">
<p>Name: <input type="text" name="Name" placeholder="Number"></p>
<p>Address: <input type="text" name="Address" placeholder="Number"></p>
<p>City: <input type="text" name="City" placeholder="Number"></p>
<p>Comment: <input type="text" name="Comment" placeholder="Number"></p>
<p><input type="submit" value="SEND"></p>
</form>
It then comes out like this:
Name=Bob&Address=something&City=more&Comment=elsemore
but what I want is:
Name=Bob
Address=something
City=more
Comment=elsemore
or even better:
Name = Bob
Address = something
City = more
Comment = elsemore
Is it at all possible currently to do this just within HTML? HTML5 and Python is all I know (mostly only the basic parts too). Maybe someone could help me out with the proper code/script on this.
I did find some other posts on this but they are old and don't answer the question.
You need to set the Encryption Type (enctype="text/plain"):
<form method="post" action="mailto:email#address.com?subject=Stuff" enctype="text/plain">
<p>Name: <input type="text" name="Name" placeholder="Number"></p>
<p>Address: <input type="text" name="Address" placeholder="Number"></p>
<p>City: <input type="text" name="City" placeholder="Number"></p>
<p>Comment: <input type="text" name="Comment" placeholder="Number"></p>
<p><input type="submit" value="SEND"></p>
</form>
You could also write some stuff in Javascript and then work with the body parameter. But i wouldn't recommend this.
In most times, it is better to let the webserver handle the email communication.
Asp: http://www.codeproject.com/Tips/371417/Send-Mail-Contact-Form-using-ASP-NET-and-Csharp
Php: http://tangledindesign.com/how-to-create-a-contact-form-using-html5-css3-and-php/

Integrating Neteller to my Asp.net website

I am banging my head for 2 days to integrate neteller into my website but could not get it,
Returned response in xml contain error saying Invalid merchantid/merchant key ,how can i get them?
<form method="post" action="https://test.api.neteller.com/netdirect">
<input type="text" name="version" value=" 4.1">
<input type="text" name="amount" size="10" value="3443" maxlength="10">
<input type="text" name="currency" value="USD" size="10" maxlength="3">
<input type="text" name="net_account" size="20" value="" maxlength="100">
<input type="text" name="secure_id" size="10" value="" maxlength="6">
<input type="hidden" name="merchant_id" value="43646">
<input type="hidden" name="merch_key" value="456453">
<input type="hidden" name="merch_transid" value="46436436" maxlength="50">
<input type="hidden" name="language_code" value="EN">
<input type="hidden" name="merch_name" value="fdghdfhgf">
<input type="hidden" name="merch_account" value="436346" maxlength="50">
<input type="hidden" name="custom_1" value="test123" maxlength="50">
<input type="hidden" name="custom_2" value="test123" maxlength="50">
<input type="hidden" name="custom_3" value="test123" maxlength="50">
<button type="submit" name="submit">Make Transfer</button>
</form>
At first You should not put your merchant credentials in hidden inputs for security reasons. Everyone can see your sensitive data. Make a POST on server side not client side.
merchant API key You can generate on merchant neteller panel in the Developer tab.