How to get Yodlee FastLink URL with Java HTTP request code? - apache-httpclient-4.x

I'm testing out Yodlee. I'm able to get FastLink working via POSTing a FORM element in my Chrome browser. I believe there is some type of redirect happening after the POST that tells Chrome to go to another URL address and that page loads. I want to do the POST with Java code and capture the redirect URL.
I've tried with the below RestTemplate code but the request hangs and the connection is eventually killed.
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("rsession", getUserAuthToken());
map.add("token", fastLinkAccess.getAccessToken());
map.add("app", "10003600");
map.add("redirectReq", "true");
URI uri = template.postForLocation("https://node.developer.yodlee.com/authenticate/restserver/", map, String.class);
How can I go about this?

It will be possible to launch Fastlink by posting HTML content to the action(node) URL only.
As you are using java, you can use the following sample code to post a HTML using java-
String formHtmlContent = "<div class='center processText'>Processing...</div>"
+ "<div>"
+ "<form action='${NODE_URL}' method='post' id='rsessionPost'>"
+ " RSession : <input type='text' name='rsession' placeholder='rsession' value='${RSESSION}' id='rsession'/><br/>"
+ " FinappId : <input type='text' name='app' placeholder='FinappId' value='${FINAPP_ID}' id='finappId'/><br/>"
+ " Redirect : <input type='text' name='redirectReq' placeholder='true/false' value='true'/><br/>"
+ " Token : <input type='text' name='token' placeholder='token' value='${TOKEN}' id='token'/><br/>"
+ " Extra Params : <input type='text' name='extraParams' placeholder='Extra Params' value='${EXTRA_PARAMS}' id='extraParams'/><br/>"
+ "</form></div><script>document.getElementById('rsessionPost').submit();</script>";

Related

"Send" Button linked to contact form

I have a contact form in my webpage with 3 areas of name, e-mail and text (no subject), and a send button underneath the form. What should I do to make the button work? I want the user to write their Name (which would eventually become the subject of the e-mail), their e-mail and the text they want to send and I want to receive the e-mail from them with their name as a subject, their e-mail and the text they would have written as the body of the e-mail. Plus, I don't want the button to open the users e-mail, like outlook etc. I want it to happent silently. So the outcome would be the user writes the text in the contact form, presses send and then I get the e-mail.
Thank you a lot, in advance!!!
Rafael.
First you have to learn php to make it work. You can not send mail using only form design.
Also, you have to upload your files on the server. Sending mail requires SMTP, which will not work on localhost.
HTML:
<form action="mail_handler.php" method="
FullName: <input type="text" name="full_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
mail_handler.php
<?php
if(isset($_POST['submit'])){
$to = "email#example.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$full_name = $_POST['full_name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $full_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $full_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $full_name . ", we will contact you";
}
?>
I suggest you to watch some tutorial before implementing it. You need to understand php before implementing it.

Form will not send Information

So I have been sitting here racking my brain for a few hours and just cannot seem to find what I have wrong here. I am trying to get my form to send the information that the user inputs to my email. When I click send nothing happens... Anything would help! Thanks!
Here is the code I have atm:
Email me!
<div class="formCenter">
<form action="MAILTO:myemail#yahoo.com" method="post" enctype="text/plain">
First Name:<br>
<input type="text" name="firstName"><br>
Last Name:<br>
<input type="text" name="lastName"><br>
Email:<br>
<input type="text" name="email"><br>
Comments:<br>
<textarea name="commentBox" rows="6" cols="40"></textarea><br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
</div>
Okay so you have to send the Action to a page like Email.PHP (or ASP.net ect) which will process your POST variables.
Example:
<?php
$firstame = $_POST['firstName'];
?>
You then have to use Mail(), which will work on most servers but sometimes it won't so you can use a tool like PHPMailer which is an object orientated tool.
As you are providing the link as MAILTO, it opens up your local mail client to send an email with the POST variables listed, which is very unprofessional at best. You are better off having a link that goes to MAILTO for the time being, perhaps with a hidden value like or something like that, so when they open the client it automatically generates an email that they can just click. With that being said, you would keep your form layout as it is, but just swap out variables so they don't appear.
The reason you didn't see anything when you clicked Send is because even though your TYPE is a submit, you sometimes need the Value and/or Name to be Submit. Some browsers and servers will treat it differently, even frameworks like Bootsrap. If you change your name and value to Submit then change one back to Send to see what works for you, you can keep it in the Send format, given that it works.
I hope this helps.
you can try this one:
<?php
if($_POST["message"]) {
mail("your#email.address", "Form to email message", $_POST["message"], "From: an#email.address");
}
?>
see this page http://htmldog.com/techniques/formtoemail/
The form itself is not able to send the email. What the code does is prompts you to select email client software such as Outlook.
Did you check whether your email client software work properly? A reboot of machine is also a mean of troubleshooting.
JavaScript
function submitEmail() {
var fname = $.trim($("#txtfname").val());
var lname = $.trim($("#txtlname").val());
var email = $.trim($("#txtemail").val());
var comments = $.trim($("#txtComments").val());
if (isValidEmail(email) && (fname.length > 1) && (lname.length > 1)) {
$.ajax({
type: "POST",
url: "index.aspx/SubmitEmail",
data: "{'Email':'" + $.trim($("#txtemail").val()) + "'," + "'FName':'" + $.trim($("#txtfname").val()) + "'," + "'LName':'" + $.trim($("#txtlname").val()) + "'," + "'Comments':'" + $.trim($("#txtComments").val()) + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response.d != "null") {
var JsonObj = $.parseJSON(response.d);
if (JsonObj._Status == "OK") {
alert('Success Email :)')
}
else {
alert(JsonObj._Message);
}
}
},
failure: function (msg) {
alert(msg);
}
});
}
else {
return false;
}
}
function isValidEmail(emailAddress) {
var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))#((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
return pattern.test(emailAddress);
};
<WebMethod()> _
Public Shared Function SubmitEmail(ByVal Email As String, ByVal FName As String, ByVal LName As String, ByVal Comments As String) As String
Dim _serializer = New JavaScriptSerializer()
Dim jSonRes As String = String.Empty
Dim MyString As New StringBuilder()
MyString.Append("First Name: " & FName).Append(Environment.NewLine)
MyString.Append("Last Name: " & LName).Append(Environment.NewLine)
MyString.Append("Email Address: " & Email).Append(Environment.NewLine)
MyString.Append("Comments: " & Comments).Append(Environment.NewLine)
Try
Dim Message As New Net.Mail.MailMessage("Do-Not-Reply#test.com", "myemail#yahoo.com")
Message.CC.Add("test#test.com,test#test.com")
Message.Subject = "New Request from " & FName & " " & LName
Message.IsBodyHtml = False
Message.Body = MyString.ToString()
Dim SmtpMail As New System.Net.Mail.SmtpClient
SmtpMail.Host = "localhost"
SmtpMail.Send(Message)
jSonRes = _serializer.Serialize(New With {._Status = "OK", ._Message = ""})
Catch ex As Exception
jSonRes = _serializer.Serialize(New With {._Status = "Error", ._Message = ex.Message})
End Try
Return jSonRes
End Function
<form action="index.aspx/submitEmail" method="post" enctype="text/plain">
First Name:<br>
<input type="text" name="firstName" id="fname"><br>
Last Name:<br>
<input type="text" name="lastName" id="lname"><br>
Email:<br>
<input type="text" name="email" id="txtemail"><br>
Comments:<br>
<textarea name="commentBox" rows="6" cols="40" id="txtComments"></textarea><br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
This is the correct way to send a email. You can also use a php or C# code for sending a email. I have used vb.net code(webmethod) for sending email.

Dynamically create a button in aspx page

i want to make some elements in my asp form like below, unfortunately input button dose not work and "btnsave_ServerClick" dose not fire!
any body has idea?
<div class="clear"></div>
<%
string matn="";
System.Data.DataTable ds = new System.Data.DataTable();
try
{
// databaselinker is a class which is connected to the database
databaselinker link = new databaselinker();
// id is QueryString parameter
ds = link.selectplan(id);
}
catch (Exception Ex) { }
int i=0;
foreach (System.Data.DataRow DRow in ds.Rows)
{
TableRow tRow = new TableRow();
matn += "<div class='frame' id='frame" + DRow["PlanID"] + "'>";
matn += " name <input id='Text1' type='text' /> * ";
matn += "</br>";
matn += "Family <input id='Text2' type='text' /> * ";
matn += "<input id='Button1' type='button' value='Save' runat='server' onServerClick='btnsave_ServerClick' />";
matn += "</div>";
i++;
}
Response.Write(matn);
%>
When you type that button as string on this line
matn += "<input id='Button1' type='button' value='Save' runat='server' onServerClick='btnsave_ServerClick' />";
the asp.net did not know anything about that button, even if you have place the runat= is still a string.
when you have render that string using the
Response.Write(matn);
asp.net compile the response.write but NOT compile the string that you render of.
And that is the reason that is not working and not fire.
To make it work you need to create it dynamically.
Some examples on how to do it:
HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET
Dynamic Controls Made Easy in ASP.Net
Persistent dynamic control in ASP.Net

Apostrophe (Smart Quote) in search throws Apache 400 Bad Request

I have a search form in my web application that throws an Apache 400 Bad Request error when you search using an apostrophe (smart quote, i.e. ’ not '). This happens when someone copy and pastes from Microsoft Word (which automatically converts tick marks to smart quotes).
The form causes a GET request which puts the search string in the URL. Even when I encode the string, it causes this error. What should I do to get this to work?
<script type="text/javascript">
function zend_submit_main() {
var query = $('#search_field').val();
if(query != '') {
var search_field = '/query/' + escape(query);
var url = '/search/results' + search_field + '/active-tab/contacts';
window.location = url;
}
return false;
}
</script>
<form id="search_form" method="GET" onsubmit="zend_submit_main(); return false;">
<input type="text" value="search by contact name" onFocus="if (this.value=='search by contact name') { this.value=''; }" onBlur="if (this.value=='') { this.value='search by contact name'; }" name="search_field" id="search_field" style="width:160px;" />
<input type="submit" value="Go" />
</form>
Use encodeURIComponent instead of escape:
var search_field = '/query/' + encodeURIComponent(query);
escape is not a standard function and does not encode the value according to the Percent-encoding as specified by RFC 3986. ’ for example is encoded as "%u2019.

Search: what should the form page look like?

I'm new to html and am trying to implement a search function. I've created an input box and search buttons but I have no idea what the form page should look like. Please Help. Thank you!
Here's the code:
"<form name=MB method=\"POST\" action=\"formpage-->not sure what this page should look like">\n "
"<p align=MIDDLE>Search for Tokens: " + //Search Description
"<input name=\"term\" type=\"text\" onkeypress=\"if(event.keyCode==13) " +
"document.MB.exact.click();\" size=30> </p> \n" + //Search Box
"\n<FONT FACE=\"Geneva,Arial,Helvetica,lucida sans,san-serif\"><STRONG>" + //search buttons
"<input name=\"exact\" type=\"submit\" value=\"Find Exact\"" +
"\n<input name=\"AND\" type=\"submit\" value=\"Find All Tokens\">" +
"\n<input name=\"OR\" type=\"submit\" value=\"Find Any Tokens\">" +
"\n</STRONG></FONT></TD>\n</TR>\n</TABLE>\n</form>\n"
PS the reaszon it's all in quotes is because its a java program that generates the htmlenter code here
This is a pretty vague question but you probably want something like:
<form action="URL_FOR_SEARCH_HERE" method="GET">
<input type="text" name="query"/><br />
<input type="submit" value="Search"/>
</form>
(URL_FOR_SEARCH_HERE would be replaced by something like "/search.php", depending on what server-side technology you're using to do the actual search processing.)
It depends what you are searching for as well. If you are searching through a database then your form should point to some code that executes a sql search function.