kitaitoa
2 years agoContributor
How to use aqHttpRequest with utf8 encoding
I use a webservice call to manage my SQL queries during my automated tests with TestComplete.
The Dev has created the right webservice for this.
I get the response from my service in a JSON. For that I pass it in the Content-Type header: aqHttpRequest.SetHeader("Content-Type", "application/json").
I would like to pass it a utf-8 encoding as well, because I need it if my response contains accents.
I have tried several methods:
aqHttpRequest.SetHeader("Content-Type", "application/json; charset=utf-8")
But this returns a "text/html; charset utf-8. I lose the json !
or
aqHttpRequest.SetHeader("Content-Type", "application/json")
aqHttpRequest.SetHeader("Accetp-Charset", "utf-8")
It doesn't solve the encoding.
This is the full code :
function httpPostRequest(paramAdress,paramRequestBody)
{
// Lecture de l'environnement
var beginParamAdress = aqString.SubString(ProjectSuite.Variables.URL,0,aqString.Find(ProjectSuite.Variables.URL,"home.html"))
// Récupération du token
var accesToken = getAccesToken(beginParamAdress);
// Construction de l'adresse complète (environnement + WebService)
var address = beginParamAdress + paramAdress ;
// Define the request body JSON string
var requestBody = paramRequestBody ;
// Create the aqHttpRequest object
var aqHttpRequest = aqHttp.CreatePostRequest(address);
// Specify the Content-Type header value
aqHttpRequest.SetHeader("Content-Type", "application/json;charset=utf-8" );
aqHttpRequest.SetHeader("com.qualiac.auth.accessToken", accesToken);
// Send the request, create the aqHttpResponse object
var aqHttpResponse = aqHttpRequest.Send(requestBody)
// Check the response:
Log.Message("aqHttpResponse.GetHeader " + aqHttpResponse.GetHeader("Content-Type"));
Log.Message(aqHttpResponse.StatusCode); // A status code
Log.Message(aqHttpResponse.Text); // A body
Any ideas?