HTTP Response is 200 but Response Body is empty. | Community
Skip to main content
Level 3
October 4, 2023
Solved

HTTP Response is 200 but Response Body is empty.

  • October 4, 2023
  • 1 reply
  • 12170 views

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:

 

 

Thank you,
Krishna

 

 

 

 

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 AkshayAnand

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

1 reply

AkshayAnand
Community Advisor
AkshayAnandCommunity AdvisorAccepted solution
Community Advisor
October 4, 2023

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

Level 3
October 4, 2023

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

 

Thanks for the inputs.