• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CFHTTP ODD ERROR

Participant ,
May 14, 2019 May 14, 2019

Copy link to clipboard

Copied

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?

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 15, 2019 May 15, 2019

Copy link to clipboard

Copied

You should surround strings with quotes. For example,

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

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

<cfset RefToken = "239hy9uiw784fbew43y7">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 15, 2019 May 15, 2019

Copy link to clipboard

Copied

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,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 15, 2019 May 15, 2019

Copy link to clipboard

Copied

There is no need, and no value added, to use both hashes and quotes to call CF expressions that return strings.

Dave Watts, Eidolon LLC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 15, 2019 May 15, 2019

Copy link to clipboard

Copied

So is the consensus that I should surround strings with quotes. For example,

Like this?

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

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

<cfset RefToken = "239hy9uiw784fbew43y7">

What does this mean?

There is no need, and no value added, to use both hashes and quotes to call CF expressions that return strings

I have changed all of the values used in this example. They aren't real credentials.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 15, 2019 May 15, 2019

Copy link to clipboard

Copied

LATEST

It's best to use the following syntax:

<cfset AuthKey = mid(line1,19)>

<cfset RefToken = mid(line2,15)>

<cfset RefToken = "239hy9uiw784fbew43y7">

What Dave is talking about is that the following two lines are functionally equivalent, but the first line makes the parser work harder:

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

<cfset AuthKey = mid(line1,19)>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation