1

How to convert Python HTTP Post to CF HTTP Post with Basic Authentication?

There seems to be an issue with the CF HTTP Post Authentication. It can't connect to the other side.

What am I missing in the CF code?

From - Python:

import datetime
import requests
auth = ('huant','vk2014')
url = 'https://www.mytestdomain.com'

inquiry_xml = "<inquiry>
<header>
<source>VK</source>
</header>
<data>
<request_date>2014-02-25T18:48:24</request_date>
<name>Huan</name>
<total_guests>4</total_guests>
<check_in>2014-02-25</check_in>
<check_out>2014-03-25</check_out>
<comment><![CDATA[hi could u please confirm there is availability and location wise are we close to sydney city centre as we have 2 young children. look forward to hearing from you. Thanks,John]]></comment>
<property_id>201027</property_id>
<email>myemail@test.com</email>
<phone_number>07747484202</phone_number>
<newsletter_opt_in>0</newsletter_opt_in>
<user_ip>90.221.169.227</user_ip>
<point_of_sale>mydomain.com</point_of_sale>
<utm_medium>mysync</utm_medium>
<utm_source>huant</utm_source>
<utm_campaign><![CDATA[VKPost]]></utm_campaign>
</data>
</inquiry>"

r = requests.post(url, auth=auth, data={'inquiry_xml': inquiry_xml}, verify=False)
print r.status_code
print r.text

To - Coldfusion

<cfsavecontent variable="strXML">
<inquiry><header><source>VK</source></header><data><request_date>2014-01->31T18:48:24</request_date><name>Huan</name><total_guests>4</total_guests><check_in>2014-06-20</check_in><check_out>2014-06-28</check_out><comment><![CDATA[hi could u please confirm]]></comment><property_id>350278</property_id><email>myemail@test.com</email><phone_number>07747484202</phone_number><newsletter_opt_in>0</newsletter_opt_in><user_ip>90.221.169.227</user_ip><point_of_sale>mydomain.com</point_of_sale><utm_medium>mysync</utm_medium><utm_source>huant</utm_source><utm_campaign>![CDATA[VKPost]]</utm_campaign></data></inquiry>
</cfsavecontent>

<cfhttp url="https://www.mytestdomain.com" method="post" result="objGet" username="huant" password="vk2014">
<cfhttpparam type="XML" value="#strXML.trim()#"/>
</cfhttp>

<cfdump var="#objGet#">

Update from comments

I've tried

<cfhttparam type="formfield" name="inquiry_xml" value="#strXML.trim()#"> 

and it still cannot authenticate. Here's the CFDump:

Charset      [empty string] 
ErrorDetail  I/O Exception: peer not authenticated 
Filecontent  Connection Failure 
Header       [empty string] 
Mimetype     Unable to determine MIME type of file. 
Responseheader  struct [empty] 
Statuscode    Connection Failure. Status code unavailable. Text YES 
Leigh
  • 28,765
  • 10
  • 55
  • 103
  • Does not connect at all or does not process the request successfully? Also, just a guess, but it looks like the python request is sending the xml in a field named `inquiry_xml`. Try doing the same ie `` – Leigh Jan 31 '14 at 23:23
  • 2
    Have you added the SSL Cert to your Java store? A common and confusing issue when using Coldfusion with SSL is that you need the key in the java store, or the communication will fail. – Gavin Pickin Feb 01 '14 at 00:02
  • @GavinPickin - Good spot. I missed the https. – Leigh Feb 01 '14 at 02:33
  • I've tried and it still cannot authenticate. Here's the CFDump: Charset [empty string] ErrorDetail I/O Exception: peer not authenticated Filecontent Connection Failure Header [empty string] Mimetype Unable to determine MIME type of file. Responseheader struct [empty] Statuscode Connection Failure. Status code unavailable. Text YES – user3259107 Feb 02 '14 at 04:55
  • Source is Coldfusion and I'm trying to post to a vendor site https://www.mytestdomain.com and they're using Python. – user3259107 Feb 02 '14 at 05:06
  • Hi Gavin, how do I add the SSL Cert to the Java store? Which SSL Cert? – user3259107 Feb 02 '14 at 05:53
  • @user3259107 - Sending the correct data fields is only part of the problem. Do a search on that http error. There are several threads that explain how to add certs to a keystore. For example: http://stackoverflow.com/questions/1613038/coldfusion-cfhttp-i-o-exception-peer-not-authenticated-even-after-adding-cert – Leigh Feb 02 '14 at 18:29
  • Steps to install SSL cert to Java keystore - http://stackoverflow.com/a/19449937/1636917 – Miguel-F Feb 03 '14 at 14:47

0 Answers0