• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Example of cURL in coldfusion

Community Beginner ,
Apr 07, 2008 Apr 07, 2008

Copy link to clipboard

Copied

Hello,

I was wondering if someone could write a short example of using cURL with Coldfusion? Something like a page grab or a simple log in example. I'm not sure how to even start using these two together.

I'm trying to hit a third party company with a request for information that will display for a user when we receive the information. Hopefully this will be an automatic process.

Thanks,
matt
TOPICS
Advanced techniques

Views

15.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 07, 2008 Apr 07, 2008

Copy link to clipboard

Copied

<cfexecute>?

can't you do what you want with cfhttp/cfftp?

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 07, 2008 Apr 07, 2008

Copy link to clipboard

Copied

That's what I originally thought but I was unable to get their system to authenticate my requests.

I was using a action post cfhttp with all of the parameters I thought they were looking for but the only thing returned to me was a connection error.

They of course don't know Coldfusion and I don't know much about cURL. I'm trying to figure out how to get it done but my Google searches don't come up with much info.

Thanks for your question though...

matt

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2008 Apr 07, 2008

Copy link to clipboard

Copied

There is much information in the cURL FAQ. Here is a sample cURL procedure to grab a web page.

First, download cURL. I am on Windows, so I downloaded one of the binaries for Windows. I created the folder c:\curl_7_18_0 and extracted the zip file into it, such that the path of the curl application is c:\curl_7_18_0\curl.exe. I then ran a Coldfusion page containing the following code

<cfexecute name = "C:\curl7_18_0\curl.exe"
arguments = " http://www.adobe.com/"
outputfile="C:\curl7_18_0\adobePage.html"
timeout = "20">
</cfexecute>
done page grab!

When I double-click on the file C:\curl7_18_0\adobePage.html I duly get the Adobe page.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 08, 2008 Apr 08, 2008

Copy link to clipboard

Copied

Hello,

Thank you BKBK with that code I know that my cURL set up is correct and I'm usng the cfexecute correctly.

Now with my code below can I get information or am I going about things in the wrong way? This is a crudely done code snippet to show what I'm thinking of. Right now I get no errors and all I return is a blank page.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 09, 2008 Apr 09, 2008

Copy link to clipboard

Copied

Do away with the cfsavecontent and see what you get with something like this:

<cfexecute name="etc."
arguments="etc."
outputFile = "C:\temp\Stuff.txt"
</cfexecute>


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 09, 2008 Apr 09, 2008

Copy link to clipboard

Copied

Hello,

Thank you BKBK. I tried what you mention and all I received was a stuff.txt file that had nothing inside it.

Mr. Black. I was originally trying to use CFhttp and I think that would be a great way to do it. The problem I had was that it wasn't getting authenticated on their end. I had the code all set up and I used the cfhttpParams for their x_usernames and what not. I am waiting for them to e-mail me their logs so I can see what their end says is a problem.

But until then I thought I would try to use the tech they use, cURL, of which they have a lot of experience. Which doesn't really help me but I have to try something while I wait.

Thanks,
matt

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 09, 2008 Apr 09, 2008

Copy link to clipboard

Copied

It has zero sense to use cURL while you have CFHTTP available.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 10, 2008 Apr 10, 2008

Copy link to clipboard

Copied

Mr Black wrote
It has zero sense to use cURL while you have CFHTTP available.

Not zero. Knowledge makes sense.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 10, 2008 Apr 10, 2008

Copy link to clipboard

Copied

Lankeeone,
Experiment by placing the URL at the end, thus:

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 11, 2008 Apr 11, 2008

Copy link to clipboard

Copied

>>t has zero sense to use cURL while you have CFHTTP available.

>Not zero. Knowledge makes sense

O-o-ops, sorry. I was wrong. It has negative sense. There is nothing that you would be able to do with cURL and couldn't do with CFHTTP, except that you would have MUCH larger overhead with cURL (from all points of view: performace, reliablility, resources, amount of code written, etc.).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 11, 2008 Apr 11, 2008

Copy link to clipboard

Copied

Mr Black wrote
It has negative sense. There is nothing that you would be able to do with cURL and couldn't do with CFHTTP, except that you would have MUCH larger overhead with cURL (from all points of view: performace, reliablility, resources, amount of code written, etc.).

You miss my point about knowledge. By your reasoning, it makes no sense to be able to do arithmetic using pencil and paper when one can simply reach for the calculator.

There is a funny edge to this. You seem to know quite a bit about both cURL and CFHTTP. That is what enables you to weigh the pros and cons. Yet you want to discourage Lankeeone from gaining that knowledge.

The very first sentences of this thread tell us that Lankeeone is new to cURL and wishes to learn more about it. That itself is a worthy purpose.



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 15, 2008 Apr 15, 2008

Copy link to clipboard

Copied

Hello,

Sorry for the late reply I was out of the office for a while. Mr. Black I totally understand that cfhttp would be the perferred method to use in this situation. I would love to use it, but I can't get working with their system. While I await more clarification to the problems their system has with my requests I'm trying to get something done. The bosses want it done.

The third party company knows cURL and doesn't know Coldfusion.

Just for myself if I include a cfhttpparam in a cfhttp is would be like including it as a <input type hidden> in a regular form correct?

<cfhttp method="post">
<cfhttpparam name="x_username">
</cfhttp>

is roughly the same as saying

<form method="post">
<input type='hidden' name="x_username">
</form>

BKBK I will try your example soon and get back to you with the results.

Thanks for everyone's comments. I do appreciate them all.

matt

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 15, 2008 Apr 15, 2008

Copy link to clipboard

Copied

Lankeeone wrote:
> Just for myself if I include a cfhttpparam in a cfhttp is would be like
> including it as a <input type hidden> in a regular form correct?
>
> <cfhttp method="post">
> <cfhttpparam name="x_username">
> </cfhttp>
>
> is roughly the same as saying
>
> <form method="post">
> <input type='hidden' name="x_username">
> </form>

Actually it <cfhttp...> is exactly the same as the <form...>. It is
also the same as


<form method="post">
<input type="text" name="x_username">
</form>

OR

<form method="post">
<select name="x_username">...<select>
</form>

OR

<form method="post">
<input type="radio" name="x_username" value="foo">
</form>

OR
<form method="post">
<input type="checkbox" name="x_username" value="bar">
</form>

The point here is that all these form controls are only for the browser
interface. Once the form is completed the action http request simply
contains a set of name-value pairs.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 17, 2008 Apr 17, 2008

Copy link to clipboard

Copied

Hello,

BKBK, I tried the code that you put in this thread and I got a blank text file. Nothing in it at all. No errors either.

I've talked to the third party company and they said to try to use my cfhttp with http instead of https. I did that and I now get a response from their system. I do have two questions though.

1) Why does the http work and not the https? I am using Coldfusion 7 right now.

2) They return information like this

1,0
76876,127.0.0.1,0,2008-04-01,98798

I am receiving an "incorrect number of columns in row" error now. I think it's due to the fact that they have broken up the returned information. So the 1,0 is the first row and only is two columns so when Coldfusion gets to the second row and sees five columns it doesn't like it.

Though I could be incredibly wrong on that as well.

Thank you for all of your help and comments.

matt

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2008 Apr 19, 2008

Copy link to clipboard

Copied

Lankeeone wrote:
> BKBK, I tried the code that you put in this thread
> and I got a blank text file. Nothing in it at all.
> No errors either.


I have succeeded in reproducing the scenario of a blank output file. The following two points stood out:

1) Confirm that the URL you are using is actually that of the action-page of the form.

2) Verify whether the action-page has validation code like
<cfif isDefined("form.abracadabra")>
</cfif>
If so, then you will have to include &abracadabra=some_value in the data string. Otherwise the output may be blank.

Ask the webmaster.

> I am receiving an "incorrect number of columns in row"
> error now. I think it's due to the fact that they have
> broken up the returned information. So the 1,0 is the
> first row and only is two columns so when Coldfusion gets
> to the second row and sees five columns it doesn't like it.


I think so too. Coldfusion tried to build a query from the data, using the comma as delimiter, but the carriage return creates two rows with an unequal number of columns.

What happens when you leave out the name attribute from the cfhttp tag? Then Coldfusion wouldn't need to create a query.



edited: text block separated into 2 paragraphs

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 04, 2011 Aug 04, 2011

Copy link to clipboard

Copied

Ok, seriously? Do you guys claim to know anything about curl/cfhttp and dare say that you can do anything with cfhttp you can do with curl?

PUT /feeds/default/media/document%3Adocument_id
GData-Version: 3.0
Authorization: <your authorization header here>
Content-Length: 73612
Content-Type: multipart/related; boundary="END_OF_PART"
Slug: test.doc
--END_OF_PART
Content-Type: application/atom+xml

<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" gd:etag="BxAaTxRZAyp7ImBq">
  <category scheme="http://schemas.google.com/g/2005#kind"
      term="http://schemas.google.com/docs/2007#document"/>
  <title>example document</title>
</entry>

--END_OF_PART
Content-Type: application/msword

... doc contents here ...

--END_OF_PART

Even something simple like the above requires you to write the xml away to the drive _just_ to get it to work with cfhttp... and this is a ridiculously staightforward request. Next if you start looking at the uploading api's and more it requires you to manually define http params on the multipart level which seems impossible to control. This kind of stuff tends to be _simple_... with cfhttp you spend hours just to get it to work by chance.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 04, 2011 Aug 04, 2011

Copy link to clipboard

Copied

LATEST

Wow, holy angry thread resurrection Batman!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation