HttpClientRequest encoding setting | Community
Skip to main content
June 15, 2020
Solved

HttpClientRequest encoding setting

  • June 15, 2020
  • 2 replies
  • 3946 views

Hello,

 

We are doing a JS where a HttpClientRequest is used for pushing a request to another 3rd party REST API. In this request we are setting the header Content-type to application/json with charset=utf-8. However, the 3rd party that is receiving the request is not receiving it with UTF-8 encoding but in another encoding (windows-1252). Question: is there another setting other than the HttpClientRequest header that might change the encoding of a request done from ACC to another API?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Samy_doe

The way you can use HttpClientRequest is in a JS activity in a workflow and it looks like:

var request = new HttpClientRequest(url);
request.connect();
request.method = "POST";
request.body = data;
request.header["Content-Type"] = "application/json;charset=UTF-8";
request.execute();

In this request the connect() and execute() methods have some optional parameters for when the endpoint has a proxy or if you want to have a call async. Documentation here: https://docs.adobe.com/content/help/en/campaign-classic/technicalresources/api/c-HttpClientRequest.h... 

However, it seems like the way the connect and execute methods are setup up is interfering with the Content-Type header meaning that in some configuration the Content-Type set up like in the above code is ignored.
This seems to be related to the proxy setting on the ACC environment we are working in. We managed to find a working code by not setting up any optional parameters but only using connect() and execute() as they are.

2 replies

Jonathon_wodnicki
Community Advisor
Community Advisor
June 15, 2020

Hi,

 

I've never been able to get HTTPClientRequest to set content-type header.

What I've done to solve is make a drop-in replacement for HTTPClientRequest class, wrapping execCommand('curl').

HTTPClientRequest is libcurl anyway.

 

Thanks,

-Jon

Samy_doeAuthor
June 16, 2020

The way you can use HttpClientRequest is in a JS activity in a workflow and it looks like:

var request = new HttpClientRequest(url);
request.connect();
request.method = "POST";
request.body = data;
request.header["Content-Type"] = "application/json;charset=UTF-8";
request.execute();

In this request the connect() and execute() methods have some optional parameters for when the endpoint has a proxy or if you want to have a call async. Documentation here: https://docs.adobe.com/content/help/en/campaign-classic/technicalresources/api/c-HttpClientRequest.html 

However, it seems like the way the connect and execute methods are setup up is interfering with the Content-Type header meaning that in some configuration the Content-Type set up like in the above code is ignored.
This seems to be related to the proxy setting on the ACC environment we are working in. We managed to find a working code by not setting up any optional parameters but only using connect() and execute() as they are.

Samy_doeAuthorAccepted solution
June 16, 2020

The way you can use HttpClientRequest is in a JS activity in a workflow and it looks like:

var request = new HttpClientRequest(url);
request.connect();
request.method = "POST";
request.body = data;
request.header["Content-Type"] = "application/json;charset=UTF-8";
request.execute();

In this request the connect() and execute() methods have some optional parameters for when the endpoint has a proxy or if you want to have a call async. Documentation here: https://docs.adobe.com/content/help/en/campaign-classic/technicalresources/api/c-HttpClientRequest.h... 

However, it seems like the way the connect and execute methods are setup up is interfering with the Content-Type header meaning that in some configuration the Content-Type set up like in the above code is ignored.
This seems to be related to the proxy setting on the ACC environment we are working in. We managed to find a working code by not setting up any optional parameters but only using connect() and execute() as they are.

ravitejagundu
Level 3
March 4, 2022

Hi @samy_doe, @jonathon_wodnicki ,

 

I need your help here.

We are also writing the POST method for Rest API call via javascript in the Campaign Classic version to get the access token from the server.

We are having 4 parameters which are "Grant_Type", "Client_id", "Client_secret", and "Scope" needs to be send in the body of the request and using the Content_Type as "application/x-www-form-urlencoded".

Can you please help me with how to send the 4 parameters in the body? I am trying all the ways but getting the errors like "invalid_client" and "unsupported_grant_type".

Can you please help?

 

Thanks,

Raviteja Gundu.

ravitejagundu
Level 3
September 5, 2022

Hi Team,

 

The issue is resolved now. We need to send the grant type, client_id, client_secret in body as a query string. We were able to get the access token now.

http.body="grant_type=<value>&client_id=<value>&client_secret=<value>&scope=<value>";

 

Hope it will help someone.

 

Thanks,

Raviteja Gundu.