coldfusioncfhttpopenbd

Error when using CFHTTP


I have built an app on openBD using CFML. In the app I am using CFHTTP like following:

<cfcomponent output="false">
<cfprocessingdirective pageencoding="utf-8">
<cfset setEncoding("URL", "utf-8")>

  <cffunction name="search" access="remote" returnType="any" returnFormat="plain">        
      <cfargument name="q" type="string" default="" required="yes">       
      <cfargument name="rows" type="string" default="&rows=120" required="yes">   
      <cfargument name="score" type="string" default="&sort=score%20desc" required="yes">
      <cfargument name="highlight" type="string" default="&hl=true" required="yes">      
      <cfargument name="json" type="string" default="&wt=json" required="yes">
      <cfargument name="phrasehighlighter" type="string" default="&hl.usePhraseHighlighter=true" required="yes">
      <cfargument name="filtr" type="string" default="&fq=model:*" required="yes">
      <cfargument name="callbackP" type="string" required="false">

      <cfset theUrl = 'http://localhost:8090/solr/ktimatologio/select/?hl.requireFieldMatch=true&hl.fl=*&q=' & #Arguments.q# & #ARGUMENTS.rows# & #ARGUMENTS.score# & #ARGUMENTS.highlight# & #ARGUMENTS.json# & #ARGUMENTS.phrasehighlighter#>

      <cfhttp url= "#theUrl#"  result="rs"></cfhttp>
…………………
…………………
…………………
…………………
</cfcomponent>

When I run it I am getting the error: 'Failed to set URL: Invalid query'.

I am damn stuck! What does this error means? I think on Adobe’s CFML engine is working properly, but I am not sure. My "programing" quiver was run out of arrows!.I need to get this working on openBD.

With respect,

Tom

Greece


Solution

  • You should have a method argument (either GET or POST, and you should remove the port. Add the port as the port attribute to the tag, like so:

    <cfset theUrl = 'http://localhost:8090/solr/ktimatologio...' />
    <cfhttp method="get" url="#theURL#" port="8090" result="rs>
    

    You'll also be better off adding all of those querystring values as cfhttpparam tags instead of appending them on your URL, like this:

    <cfset theUrl = 'http://localhost/solr/ktimatologio/select/>
    <cfhttp method="get" url="#theURL#" port="8090" result="rs>
        <cfhttpparam type="URL" name="q" value="#Arguments.q#" />
        <cfhttpparam type="URL" name="wt" value="#Arguments.JSON" />
        .... more params ....
    </cfhttp>
    

    I would also highly recommend you remove the querystring name from the arguments. If you decide you want to change your implementation, you're going to be in trouble... Just accept the value you want to supply for each querystring value, but not the name of the value itself.