简体   繁体   中英

Get query params/string from ColdFusion request

I can't get query params inside ColdFusion component.

I tried to use:

  • <cfparam name="url.q2" default="">
  • cgi.QUERY_STRING
  • arguments

All empty

I have a component:

<cfcomponent extends="taffy.core.resource" taffy:uri="/public/test" hint="some hint about this resource">
    <cffunction name="get" access="public" output="false">
        <cfparam name="url.query_p1" default="">
        <cfparam name="url.p2" default="">

        <cfset result = structNew() />

        <cfset result['arguments'] = arguments />
        <cfset result['cgi'] = cgi />
        <cfset result['QUERY_STRING'] = cgi.QUERY_STRING />
        <cfset result['url'] = url />

        <cfreturn representationOf(result).withStatus(200) />
    </cffunction>
</cfcomponent>

And use this url for test: http://localhost/public/test?query_p=1&p2=test

As response I got:

{
    "data": {},
    "arguments": {
        "endpoint": "/public/test/",
        "type": "candidate"
    },
    "QUERY_STRING": "endpoint=/public/test/",
    "url": {
        "endpoint": "/public/test/",
        "query_p1": "",
        "p2": ""
    },
    "cgi": {
        "query_string": "endpoint=/public/test/",
        "request_url": "http://localhost/index.cfm?endpoint=/public/test/",

    }
}

How can I get something like? :

query_p=1
p2=test
...

You want something like this:

<cfcomponent extends="taffy.core.resource" taffy:uri="/public/test" hint="some hint about this resource">
<cffunction name="get" access="public" output="false">
    <cfargument name="query_p1" default="">
    <cfargument name="p2" default="">


    <cfreturn rep(arguments)>
</cffunction>
</cfcomponent>

You can see additional Taffy Examples at

https://github.com/jmohler1970/Taffy_Verbs_withCache/blob/master/resources/users/users_id.cfc

Disclaimer: This is my sample code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM