views:

1212

answers:

5

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

A: 

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

Antony
thanks I'll check that out
Rich
we tried it locally (at the remote site) and it still failed, so it's probably not the key. it's some kind of CFHTTP issue I think...
Rich
when you tried it locally, were you still using an https address? Because then it could well still be a certificate issue. CFHTTP is picky about certs
Eli
A: 

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" ?

Eli
if I set redirect to "no", cfhttp.errorDetail is empty. if I set redirect to "no", the statuscode returns is 302 "Moved Temporarily". the cfhttp.location is https://testefile.boe.ca.gov/boewebservices/verification_results.jsp which if you go to directly it returns the input form. I think coldfusion is not passing the form fields to the redirect page
Rich
A: 

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

yes, I've spoken with their developers, and in their logs they can see my post getting there.
Rich
+1  A: 

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.

jalpino
thanks Jalpino. I tried it and it did the same thing, just returned the input form page, instead of the results page.
Rich
Sorry to hear that Rich...were you testing under SSL?
jalpino
A: 

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