2

I have some XMl data, I want to use the XML data to be posted to a scheduler job so using cfhttp and cfhttpparam. But for reason after running this code I was not able to schedule a job in one of my site. Tried all the options with formfields, url and xml with no success. I was saving all my data into a xml variable using cfsavecontent and using that variable to pass into cfhttparam value. Not sure what Am I doing wrong here. Here is the below code

<cfsavecontent variable="getAllValues">
    <start_job job="/cf/ecs/get_ecspseg1_data">
        <params>
        <param name="1_script" value="#script#" />
        <param name="2_login" value="#login#"/>
        <param name="3_customer" value="#customer#"/>
        <param name="4_account" value="#account#"/>
        <param name="5_begdate" value="#begdate#"/>
        <param name="6_enddate" value="#enddate#"/>
        </params>
    </start_job>
</cfsavecontent>

<cfhttp url="http://ecs" port="4444" username="test" authType = "BASIC" password="testing*1" method="post">
    <cfhttpparam type="xml" name="testing" value="#ToString(getAllValues)#"/>
</cfhttp>

here is the updated code:

<cfsavecontent variable="getAllValues">
    <start_job job="/cf/smartecs/get_pseg1_data">
        <params>
        <param name="1_script" value="#script#" />
        <param name="2_login" value="#login#"/>
        <param name="3_customer" value="#customer#"/>
        <param name="4_account" value="#account#"/>
        <param name="5_begdate" value="#begdate#"/>
        <param name="6_enddate" value="#enddate#"/>
        </params>
    </start_job>
</cfsavecontent>

<cfhttp url="http://10.xxx.xxx.xxx" port="4444" username="myusername" authType = "BASIC" password="mypassword" method="post" >
    <cfhttpparam type="header" name="Content-Type" value="application/octet-stream">
    <cfhttpparam type="body" name="testing"  value="#getAllValues#"/>
</cfhttp>
Shawn
  • 4,758
  • 1
  • 20
  • 29
user3440782
  • 144
  • 1
  • 14
  • Is the content within your CFSaveContent "CFOutputted"? If not, the values you want won't be used. (You may also have to format the dates into the acceptable format or a default ODBC-like format may be used.) – James Moberg Oct 31 '18 at 14:51
  • Yes it is sourrounded with – user3440782 Oct 31 '18 at 15:00
  • I am passing only the script name and rest all values are default or empty values – user3440782 Oct 31 '18 at 15:02
  • 1
    You may need to change "type" for your XML string to "body" and potentially set a "content-type" header. Maybe pass "content-length" too. Depending on which version of ColdFusion (you didn't mention), if older, set header "TE" to "deflate;q=0". – James Moberg Oct 31 '18 at 15:06
  • Updated the code with suggested one. Still no good – user3440782 Oct 31 '18 at 16:07
  • Between tried with atom+xml for content-Type too – user3440782 Oct 31 '18 at 16:09
  • I would dump out values to ensure you are sending what you are expecting. I'd also report on the error message you are receiving from the API endpoint. (I've also had to pass `encoded="no"` in the body to prevent CF from encoding the XML.) What API/service are you posting to? There may be some unique requirements. – James Moberg Oct 31 '18 at 16:11
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/182883/discussion-between-user3440782-and-james-moberg). – user3440782 Oct 31 '18 at 16:14
  • I removed your username and password from your code. Gotta watch out for that. Even though you're connecting to an internal machine, I'd recommend changing them. – Shawn Oct 31 '18 at 16:22

1 Answers1

0

When using a different Port number we need to even keep a / at the end of the URL. When I kept that / at the end of the URL it worked like a charm. ColdFusion will not accept : in the URL.

user3440782
  • 144
  • 1
  • 14
  • Where was the ":" in your original URL? – Shawn Oct 31 '18 at 21:15
  • When using a port number you we will write the URL as http://10.xx.xx.xx:portNumber. as we had a Portnumber attribute we cannot include that in URL. – user3440782 Nov 01 '18 at 15:43
  • Gotcha. Didn't see that in the original question. Is your mapping for `ecs/` instead of `ecs`? Did you still have to use the `/` when using the IP address? I didn't think the `/` was required. :-/ – Shawn Nov 02 '18 at 13:22
  • Yes it is Required.. when the URL had a Port number we need to keep a / beside the URL.. it is weird though .. – user3440782 Nov 05 '18 at 22:10