0
votes

I am trying to learn cf.http and cf.query from here.

I tried following code:

<cfscript>
    result = CF.http({method:"get", url:"http://google.com" });
</cfscript>
<cfdump var="#result#">

But I get error:

Invalid CFML construct found on line 2 at column 33.

FYI: my coldfusion server version: 9,0,1,274733

What would be the issue?

3

3 Answers

7
votes

Check the ColdFusion docs: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSe9cbe5cf462523a0693d5dae123bcd28f6d-7ff8.html and this blog post.

There's no CF prefix, it's a stateful object created using the new keyword, and no struct literal syntax in the constructor - just pass name value pairs.

<cfscript>
httpService = new http(url="http://www.google.com", method="get");
result = httpService.send().getPrefix();
writeDump(result);
</cfscript>
3
votes

As Peter touched on, the code you have provided is a mishmash of some sample ACTIONSCRIPT code, mixed in with CFML. This is never going to work.

The page you point to in the docs is about writing server-side ActionScript. If that's actually what you're trying to do (I suspect not) then you need to follow through the rest of the docs, starting from here http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-5df0.html.

If you're just trying to learn how to use Http.cfc and Query.cfc, then you should look at the correct part of the docs: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSe9cbe5cf462523a0693d5dae123bcd28f6d-8000.html

But no matter what you do, you can't mix ActionScript and CFML in the same file like that.

0
votes

Re: the "Invalid CFML construct". It's worth noting, this:

http({method:"get", url:"http://google.com" });

should have been this:

http(method:"get", url:"http://google.com");

or this

http(argumentCollection={method="get", url="http://google.com"});

You can define structures using {key:"value"}, {key="value"} and {"key"="value"}.

(If you wrap the key in quotes, it will be case sensitive when dumped or serialized)

You can call methods using function("value"), function(key:"value"), function(key="value") and function(key1={key2="value2"})

If you want to nest structures you must use the {key="value"} or {"key"="value"} style. eg. {"key1"={key2="value2"}}

You can even mix arrays and structs. {key1={"key2"=["a","b","c"]}}

Ben Nadel's blog post sums it up.

http://www.bennadel.com/blog/1993-Using-Dynamic-Keys-In-ColdFusion-9-s-Implicit-Struct-Creation.htm