Solved

Coldfusion Error: The toString method was not found

Posted on 2016-08-06
5
68 Views
Last Modified: 2016-08-06
Hello experts
I recently intalled Coldfusion 2016 Developer edition and while i was  trying to use the toString function as i was doing until now with CF9 i got the error: The toString method was not found
Any help?
error line:
 <cfset utf8Response = response.fileContent.toString("UTF8")>
0
Comment
Question by:Panos
  • 3
  • 2
5 Comments
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 500 total points
ID: 41745598
Edit - Added code

Sounds like response.fileContent contains a different type of object than the code was expecting? If you dump it, what does it actually contain - string, binary, null ...?

Type: <cfdump var="#response.fileContent.getClass().getName()#">
Value: <cfdump var="#response.fileContent#">

Side note, why was the CF9 code using the java method toString("UTF8")? Normally the fileContent already is a string (or sometimes binary)?
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 41745609
I'd guess it's returning a byte array. That type of object doesn't have a ToString() method, hence the error.  Test whether the result IsBinary(). If yes, use charsetEncode() to convert it to a string:

<!--- deliberately force response to be binary --->
 <cfhttp url="http://api.openweathermap.org/data/2.5/find?=San+Fransico&mode=json"
          method="GET"
          getAsBinary="yes"
          result="response" / >
 
 <cfif isBinary(response.filecontent)>
        <cfset responseString = charsetEncode(response.filecontent, "utf-8")>
 <cfelse>
        <cfset responseString = response.filecontent>
 </cfif>

  DEBUG
 <cfoutput>
     <br>class = #response.filecontent.getClass().name#
     <br>value = #responseString#
 </cfoutput>

Open in new window

0
 
LVL 2

Author Comment

by:Panos
ID: 41745620
Hi agx.
Thank you very much for your help.
It is really a binary response.
I don't know how i was confused with CF9.
The problem is fixed.
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 41745623
Thank you again
regards Panos
0
 
LVL 52

Expert Comment

by:_agx_
ID: 41745634
>> don't know how i was confused with CF9

Well if the exact same code and url work w/CF9, but not CF2016, it's entirely possible Adobe changed something.  Wouldn't be the first time.  Anyway, glad it helped.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Fixing some Issues with regex again 9 34
https json cfhttp post 1 117
Coldfusion reading Excel file translates ñ into n 4 68
Coldfusion retrieve dynamic values 1 36
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question