Alan
09/23/2024, 8:46 PMreturnFormat=json
on a remote method in a cfc, the content type is still HTML. shouldn't everything with returnFormat=json
return it with the correct response header ?Alan
09/23/2024, 8:46 PMbdw429s
09/23/2024, 8:46 PMbdw429s
09/23/2024, 8:46 PMbdw429s
09/23/2024, 8:46 PMAlan
09/23/2024, 8:47 PMAlan
09/23/2024, 8:47 PMAlan
09/23/2024, 8:47 PMbdw429s
09/23/2024, 8:47 PMbdw429s
09/23/2024, 8:47 PMbdw429s
09/23/2024, 8:48 PMAlan
09/23/2024, 8:50 PMAlan
09/23/2024, 8:50 PMAlan
09/23/2024, 8:50 PMAlan
09/23/2024, 8:50 PMAlan
09/23/2024, 8:51 PMreturn
syntaxbdw429s
09/23/2024, 8:53 PMAlan
09/23/2024, 8:53 PMAlan
09/23/2024, 8:53 PMbdw429s
09/23/2024, 8:53 PMwriteDump( getPageContext().getResponse().getHeader("Content-Type") )
cfheader( name="Content-Type", value="text/html" );
writeDump( getPageContext().getResponse().getHeader("Content-Type") )
Alan
09/23/2024, 8:55 PMAlan
09/23/2024, 8:56 PMAlan
09/23/2024, 8:56 PMbdw429s
09/23/2024, 8:56 PMbdw429s
09/23/2024, 8:56 PMAlan
09/23/2024, 8:57 PMreturnFormat=json
really is setbdw429s
09/23/2024, 8:57 PMAlan
09/23/2024, 8:57 PMAlan
09/23/2024, 8:57 PMAlan
09/23/2024, 8:57 PMbdw429s
09/23/2024, 8:58 PMAlan
09/23/2024, 8:58 PMAlan
09/23/2024, 9:00 PMAlan
09/23/2024, 9:01 PMgetChannels
doesn't have the cfheader set in the functionAlan
09/23/2024, 9:01 PMbdw429s
09/23/2024, 9:12 PMbkbk
09/25/2024, 9:14 AMreturntype
? That is perhaps the crux of the matter.
ColdFusion usually makes a guess as to the return format. For example, should the returned object be a struct, ColdFusion would return a JSON by default. That is, whether you specify returnformat
or not.
It might be that, in your case, ColdFusion cannot workout what the returntype
is or cannot convert the returned object to JSON.Alan
09/25/2024, 9:15 AMstruct
Alan
09/25/2024, 9:16 AMreturnFormat=json
is specifiedAlan
09/25/2024, 9:17 AM<struct>
for example in the markupAlan
09/25/2024, 9:18 AMAlan
09/25/2024, 9:18 AMreturnFormat=json
works fine. It's just the response content type is wrongbkbk
09/25/2024, 9:39 AMcfheader(name="Content-Type", value="application/json")
Alan
09/25/2024, 9:40 AMreturnFormat=json
is specifiedbkbk
09/25/2024, 9:43 AMbdw429s
09/25/2024, 1:08 PMbdw429s
09/25/2024, 1:09 PMbdw429s
09/25/2024, 1:10 PMAlan
09/25/2024, 1:11 PMwddx
?bdw429s
09/25/2024, 1:11 PMbdw429s
09/25/2024, 1:12 PMAlan
09/25/2024, 1:13 PMAlan
09/25/2024, 1:13 PMreturnFormat=json
Alan
09/25/2024, 1:14 PMContent-Type
bdw429s
09/25/2024, 1:14 PMAlan
09/25/2024, 1:14 PMhtml
regardless of what the returnformat isbdw429s
09/25/2024, 1:14 PMAlan
09/25/2024, 1:15 PMreturnFormat=json
returns valid json, but with the text/html
content type.
likewise, omitting it, returns presuambly valid wddx but again with `text/html`content tpyeAlan
09/25/2024, 1:15 PMtext/json
and I guess the other to be xml
bdw429s
09/25/2024, 1:16 PMAlan
09/25/2024, 1:16 PMAlan
09/25/2024, 1:16 PMreturnFormat=json
has been specified and set the content type appropiately?bdw429s
09/25/2024, 1:16 PMbdw429s
09/25/2024, 1:17 PMAlan
09/25/2024, 1:17 PMAlan
09/25/2024, 1:17 PMbdw429s
09/25/2024, 1:17 PMAlan
09/25/2024, 1:18 PMbdw429s
09/25/2024, 1:18 PMbdw429s
09/25/2024, 1:19 PMbdw429s
09/25/2024, 1:19 PMbdw429s
09/25/2024, 1:20 PMbdw429s
09/25/2024, 1:21 PMAlan
09/25/2024, 1:25 PMonCFCrequest
?bdw429s
09/25/2024, 1:26 PMbdw429s
09/25/2024, 1:26 PMAlan
09/25/2024, 1:40 PMremote
& returnFormat=json
Alan
09/25/2024, 1:40 PMbdw429s
09/25/2024, 1:40 PMbdw429s
09/25/2024, 1:40 PMAlan
09/25/2024, 1:42 PMAlan
09/25/2024, 1:42 PMAlan
09/25/2024, 1:48 PMAlan
09/25/2024, 1:54 PMpublic function onCFCRequest(string cfc, string method, struct args) {
var component = createObject("component", arguments.cfc);
var meta = getMetaData(component[method]);
if (
meta.keyExists("access")
&& meta.access == "remote"
&& URL.keyExists("returnFormat")
&& URL.returnFormat == "json") {
cfheader( name="Content-Type", value="text/json" );
}
return component[method](args);
}
Alan
09/25/2024, 1:56 PMbkbk
09/25/2024, 3:01 PMAlan
09/25/2024, 3:03 PMAlan
09/25/2024, 3:03 PMapplication/json
Alan
09/25/2024, 3:12 PMAlan
09/25/2024, 3:12 PMbkbk
09/25/2024, 3:13 PM@bdw429s: ...you were getting a wddx returnformat which is the default
That was the one. Thanks for the reminder, @bdw429s.bdw429s
09/25/2024, 3:14 PMbdw429s
09/25/2024, 3:15 PMbdw429s
09/25/2024, 3:15 PMAlan
09/25/2024, 3:15 PMAlan
09/25/2024, 3:15 PMAlan
09/25/2024, 3:17 PMbkbk
09/25/2024, 3:17 PMcomponent
as a variable name.Alan
09/25/2024, 3:17 PM