Skip to main content
Inspiring
May 14, 2019
Question

CFHTTP ODD ERROR

  • May 14, 2019
  • 1 reply
  • 1348 views

I have this code
Example #1

<cffile action = "read" file = "./config.txt" variable = "fileContents">

<cfset line1 = listGetAt(fileContents, 1, chr(10))>

<cfset line2 = listGetAt(fileContents, 2, chr(10))>

<cfset AuthKey = #mid(line1,19)#>

<cfset RefToken = #mid(line2,15)#>

<cfset contentBody = "grant_type=refresh_token&client_id=bcbb1365893&client_secret=62b5a8a84567992666tf986a3f474791e&refresh_token=9312beb987fbd8efebf6dc&scope=read%2Bwrite" />

<cfhttp method="POST" url="https://api.wedoo.com/oauth2/access_token">

<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded" />

<cfhttpparam type="formfield" name="grant_type" value="refresh_token" />

<cfhttpparam type="formfield" name="client_id" value="bcqq13f2d1d320543524">

<cfhttpparam type="formfield" name="client_secret" value="62b5a8a84567992666tf986a3f474791e" />

<cfhttpparam type="formfield" name="scope" value="read+write" />

<cfhttpparam type="formfield" name="refresh_token" value="#RefToken#" />

</cfhttp>

<cfset cfData = cfhttp.filecontent />

<cfoutput>#cfData#</cfoutput>

When I run this code I get a 500 error. I'm on a Railo server so I don't get any more info.

I can confirm the RefToken  value from line 5 is 239hy9uiw784fbew43y7

-------------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------------------------

But when I actually put the RefToken value in the code it works fine..like this
Example #2
<cffile action = "read" file = "./config.txt" variable = "fileContents">
<cfset line1 = listGetAt(fileContents, 1, chr(10))>

<cfset line2 = listGetAt(fileContents, 2, chr(10))>

<cfset AuthKey = #mid(line1,19)#>

<cfset RefToken = #mid(line2,15)#>

<cfset RefToken = 239hy9uiw784fbew43y7>

<cfset contentBody = "grant_type=refresh_token&client_id=bcbb1365893&client_secret=62b5a8a84567992666tf986a3f474791e&refresh_token=9312beb987fbd8efebf6dc&scope=read%2Bwrite" />

<cfhttp method="POST" url="https://api.wedoo.com/oauth2/access_token">

<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded" />

<cfhttpparam type="formfield" name="grant_type" value="refresh_token" />

<cfhttpparam type="formfield" name="client_id" value="bcqq13f2d1d320543524">

<cfhttpparam type="formfield" name="client_secret" value="62b5a8a84567992666tf986a3f474791e" />

<cfhttpparam type="formfield" name="scope" value="read+write" />

<cfhttpparam type="formfield" name="refresh_token" value="239hy9uiw784fbew43y7" />

</cfhttp>

<cfset cfData = cfhttp.filecontent />

<cfoutput>#cfData#</cfoutput>

When I actually put the refresh_token value in the code like in example #2 it works fine.

  1. Has anyone ever encountered this?
  2. Do I have a single quote double quote issue?
  3. Do I need to encode the RefToken value when its inside cfhttp tag?
  4. Are there other parameters that I could add to the cfhttpparam  tag?
  5. Is there another step I need to take when setting the RefToken value?
This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
May 15, 2019

You should surround strings with quotes. For example,

<cfset AuthKey = "#mid(line1,19)#">

<cfset RefToken = "#mid(line2,15)#">

<cfset RefToken = "239hy9uiw784fbew43y7">

WolfShade
Legend
May 15, 2019

BKBK  wrote

You should surround strings with quotes. For example,

Or do away with the hashtags and the quotes.

Also, OP might want to redact the original post to remove sensitive information like CLIENTID and CLIENT_SECRET, which I assume are login credentials.

V/r,

^ _ ^