Forum Discussion

djondinium's avatar
2 years ago

http.client.request post() issue

Hi,

I'm trying to connect to graphql and trying to do the authorization first. However, I keep on getting error like "html found in response" and if I try to get the content of such a response, getting "302 found".

This is what I'm using:

 

<#assign response = http.client.request(protocol, host, url).body("{ 'grant_type':'refresh_token', 'refresh_token':'${upAuth.refreshToken}', 'client_id':'${upAuth.clientId}', 'client_secret':'${upAuth.clientSecret}' }", "application/x-www-form-urlencoded").post()>

 

refresh_token is value from the cookie -- oauth2v2_bunch_of_characters_here that was set up by a javascript function.

Tried adding parameters, headers, change body content type to application/json, basically anything that I can come up with, but none seem to work.

Domain is whitelisted as well. 

I'm able to do everything with jquery and ajax, just not with the http.client.request with the same parameters. Would opt out doing it that way, but need to protect client id and client secret values.

What am I doing wrong here? Any help is appreciated.

  • Hello djondinium 

    Not really sure why are you passing three parameters in http.client.request - protocol, host, url. 


    Can you simply use following call with just one parameter url and see if that works:

    <#assign response = http.client.request(url).body("{ 'grant_type':'refresh_token', 'refresh_token':'${upAuth.refreshToken}', 'client_id':'${upAuth.clientId}', 'client_secret':'${upAuth.clientSecret}' }", "application/x-www-form-urlencoded").post()>

     
    Regards,

    Abhishek Gupta

    • MatK's avatar
      MatK
      Khoros Staff

      djondinium Have you tried changing the body to be formatted for the "application/x-www-form-urlencoded" contentType?

       

      <#assign req = http.client.request(protocol, host, url).body("grant_type=refresh_token&refresh_token=${upAuth.refreshToken}&client_id=${upAuth.clientId}&client_secret=${upAuth.clientSecret}", "application/x-www-form-urlencoded").post() />