3
votes

I want to log in (https://pacer.login.uscourts.gov/csologin/login.jsf) using CFHTTP.Using Http Live Header we have collect all required parameter and post to the login url.Here is my Example Code:

<cfhttp url="#arguments.login_url#" method="post" timeout="30" redirect="no" resolveURL="yes" useragent="Mozilla/5.0">
  <cfhttpparam name="login" value="login" type="formField">
  <cfhttpparam name="login:loginName"value="xxxx"type="formField">                      
  <cfhttpparam name="login:password" value="xxxx" type="formField">
  <cfhttpparam name="login:clientCode" value="" type="formField">
  <cfhttpparam name="login:Aj_idt206" value="" type="formField">
  <cfhttpparam type="formField" name="javax.faces.ViewState" value="stateless">
</cfhttp>

After trying above code we have get same login page content.How to log in above Mention Url and collected all cookies,session after login. Anyone have any ideas or any clue or any other method in CF?

thanks

Atu

1
Did you search first? :) This was the very first result for "cfhttp cookies" bennadel.com/blog/… . Sounds like exactly what you are trying to do.. If not, please update your question with more details. - Leigh
You may have a good bit more to do here. The page in question is complex and contains lots of JS. Do you know for certain you have trapped the fields to pass? Is your attempt above the result of simply looking at the form itself? What about headers and cookies to pass. What about redirects? What do you see when you do <cfdump var="#cfhttp#"/> - any clues there? This is going to be trial and error. - Mark A Kruger
@Mark A Kruger:how to pass header and cookies? please explain.how to extract header and cookies from above URl.I have <cfdump var="#cfhttp#"> use this after above code. - Atul Thakre
Atu, read the documentation for <cfhttpparam ..> - headers and cookies are just other kinds of resources that are part of an http request. Both HEADER and COOKIE types are supported by cfhttpparam. - Mark A Kruger
@AtuTha I made a couple of small modifications to Ben Nadel's CfHttpSession component (see Leigh's comment above) and used it to great effect for performing unit-testing on a site that requires the user to log in. It gets the login form, submits the completed form, and browses to the page against which the testing is being performed. It wouldn't be able to do this if it weren't retrieving and attaching the cookie information. - Paul Rowe

1 Answers

0
votes

I think you first have to do a get request to start a new session and then do the post using the JSESSIONID you got from the get request:

<cfhttp url="https://pacer.login.uscourts.gov/csologin/login.jsf" method="get" timeout="30" redirect="no" resolveURL="yes" useragent="Mozilla/5.0">
</cfhttp>

<cfset setcookies = cfhttp['Responseheader']['set-cookie']>

<cfhttp url="https://pacer.login.uscourts.gov/csologin/login.jsf" method="post" timeout="30" redirect="no" resolveURL="yes" useragent="Mozilla/5.0">
    <cfhttpparam name="login" value="login" type="formField">
    <cfhttpparam name="login:loginName"value="xxxx"type="formField">                      
    <cfhttpparam name="login:password" value="xxxx" type="formField">
    <cfhttpparam name="login:clientCode" value="" type="formField">
    <cfhttpparam name="login:Aj_idt206" value="" type="formField">
    <cfhttpparam type="formField" name="javax.faces.ViewState" value="stateless">
    <cfhttpparam type="header" name="Cookie" value="#setcookies#">
</cfhttp>