4
votes

I am using ColdFusion 8. I am trying to use CFHTTP Post to submit the form at this page without a user having to enter the number and click Submit. https://testefile.boe.ca.gov/boewebservices/verification.jsp?action=SALES

I've done with before with other forms, it's usually not a problem.

Here's my code:

<cfhttp url="https://testefile.boe.ca.gov/boewebservices/servlet/BOEVerification" method="POST" port="443" resolveurl="yes" redirect="yes">
<cfhttpparam type="FORMFIELD" name="type" value="SALES">
<cfhttpparam type="FORMFIELD" name="account" value="10003">
<cfhttpparam type="FORMFIELD" name="Submit" value="Submit+Request">
</cfhttp>

<Cfoutput>#cfhttp.fileContent#</CFOUTPUT>

<cfdump var="#cfhttp#">

If you try the form manually, and enter account number 10003, it returns a results page https://testefile.boe.ca.gov/boewebservices/verification_results.jsp

But when I use CFHTTP Post, it just returns the input page https://testefile.boe.ca.gov/boewebservices/verification.jsp?action=SALES

One of their developers made a Java page to do the same thing I'm trying to do, and it worked. Unfortunately, I don't know Java.

thanks,

Rich

5
Can you share the Java code that worked?Patrick McElhaney
the code is too big to add as a comment. I tried adding a new response below, but stackoverflow thought I was answering my own question. I'll prepare a link to it.Rich

5 Answers

2
votes

Hey Rich, the reason why you are being shown the form instead of your expected results is because the "verification.jsp" template expects you to have a valid session when you hit it to view the results. <cfhttp> does not maintain state on it's own, so a project like Ben Nadel's CFHttpSession.cfc might help. CFHttpSession will manage cookies (and thus session) inbetween <cfhttp> calls by interpreting Set-Cookie header results and adding them back in on subsequent calls.

One other thing that I noticed when looking at the server's response headers was that the session cookie (jsessionId) was being set to 'secure'. This means that the cookie can only be used by secured connections. I don't have SSL set up in my test environment so my attempts in using Ben's object failed, but I would think that there is a good chance for it work if you can test under an SSL connection.

Here is the simple test I did using Ben's project:

<!--- CFHttpSession does not follow redirects, this is why two calls are needed --->
<cfset objHttpSession = CreateObject("component","CFHTTPSession").Init() />

<cfset objResponse = objHttpSession.NewRequest( "https://testefile.boe.ca.gov/boewebservices/servlet/BOEVerification" )
 .AddFormField( "type", "SALES" )
 .AddFormField( "account", 10003 )
 .AddFormField( "Submit", "Submit+Request" )
 .Post()/>

<cfset objResponse = objHttpSession
 .NewRequest( "https://testefile.boe.ca.gov/boewebservices/verification.jsp" )
 .get() />

<cfoutput>#objResponse.filecontent#</cfoutput>

** It might also be necessary to make a another http call prior to the others to establish the session before your post.

0
votes

It could be due to the https address. You will probably need to import the certificate into the java keystore to successfully connect. Try this post for the process to add the certificate: http://www.coldfusionmuse.com/index.cfm/2005/1/29/keystore

0
votes

I'm guessing you're getting the input page because the server is redirecting you. Is there anything useful in cfhttp.errordetail if you set redirect to "no" ?

0
votes

So is the data actually being submitted to the BOEVerification page, or does it never get that far?

0
votes

I was having the same issue, and added the CFID and Token to the request: and got my code to work.