Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

HTTP Response is 200 but Response Body is empty.

Avatar

Level 3

Hello,

I've created a simple script for sending a POST request to an API with the "application/x-www-form-urlencoded" content type. Here's the script:


var http = new HttpClientRequest("URL");
http.header["Content-Type"] = "application/x-www-form-urlencoded";
http.header["Cache-control"] = "no-cache";
http.header["Connection"] = "keep-alive";
http.body = "param1=value1&param2=value2&param3=value3&param4=value4";

http.method = "POST";

http.execute();

logInfo(http.response.code);
logInfo(JSON.stringify(http.response));

http.disconnect();

When I run this script, I receive a response with a 200 status code, but the response body is empty.

I've reached out to the API technical team, and they have tested the API from their end. They confirmed that they are receiving the request correctly and sending a proper response.

Please note that we have also added the URL to the "urlpermissions" in the control panel.

Could this issue be related to the "application/x-www-form-urlencoded" content type? I would appreciate it if someone could review this and share their thoughts.

 

Screenshot:

krishnakanth_patnaik_cc_0-1696411767877.png

 

 

Thank you,
Krishna

 

 

 

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @krishnakanth_patnaik_cc 

 

Could you please try printing the body of the response, as "var result = http.response.body.toString();" or if the response is in JSON object try parsing it and then printing them "var result3 = JSON.parse(http.response.body);" . Also you can try the same connection once in POSTMAN to see a clear picture and connection parameters.

 

Regards

Akshay

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @krishnakanth_patnaik_cc 

 

Could you please try printing the body of the response, as "var result = http.response.body.toString();" or if the response is in JSON object try parsing it and then printing them "var result3 = JSON.parse(http.response.body);" . Also you can try the same connection once in POSTMAN to see a clear picture and connection parameters.

 

Regards

Akshay

"var result = http.response.body.toString();" this worked. Not sure why the JSON.stringify had an issue with this.

 

Thanks for the inputs.