Solved

Coldfusion Error: The toString method was not found

Posted on 2016-08-06
5
95 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

728 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