Reputation: 167
I have a project that is requiring me to Post login data to another domain. After the form submission a cookie is set in the browser and the user is redirected.
I've been able to accomplish this with javascript as follows:
<cfsavecontent variable="headOUT">
<script type="text/javascript">
function redirectPost(url, data) {
var form = document.createElement('form');
document.body.appendChild(form);
form.method = 'post';
form.action = url;
for (var name in data) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = name;
input.value = data[name];
form.appendChild(input);
}
form.submit();
}
</script>
</cfsavecontent>
<cfhtmlhead text="#headOUT#">
<cfset htmlOUT = ''>
<cfset htmlOUT = htmlOUT & '<script type="text/javascript">'>
<cfset htmlOUT = htmlOUT & "redirectPost('#remote_url#', { authen_token: '#encryptedString#' });">
<cfset htmlOUT = htmlOUT & '</script>'>
<cfoutput>#htmlOUT#</cfoutput>
If I use cfhttp:
<cfhttp method="Post" url="#remote_url#" RESOLVEURL="Yes">
<cfhttpparam type="Formfield" name="authen_token" value="#encryptedString#">
</cfhttp>
The response does not include a cookie it is only the HTML with the meta redirect as if I logged-in from their page. But with no cookie I'm not authenticated.
Is there a way to do a redirect and a post with cfhttp and/or cflocation or is the javascript the best solution?
Upvotes: 0
Views: 312