Unexpected behavior from remote host: Unbuffered entity enclosing request can not be repeated.

adityadev
ServiceNow Employee
ServiceNow Employee

I get the above error when running the following code:

var r = new sn_ws.RESTMessageV2();

r.setHttpMethod('post');

r.setBasicAuth('<username>', '<password>');

r.setEndpoint('<instance>/api/now/attachment/file');  

r.setRequestBodyFromAttachment('<attachment sys_id from local instance>');

var response = r.execute();

gs.info(response.getStatusCode());

gs.info(response.getBody());

Output:

Unexpected behavior from remote host: Unbuffered entity enclosing request can not be repeated.

Response:

Status Code: 0

Body:

I'm essentially trying to upload attachments from local records to another instance.

Any suggestions/corrections? I'm unable to understand the error and am fairly new to developing on ServiceNow

1 ACCEPTED SOLUTION

Thanks aakashshah!



Your links were very useful and while they did not directly get me the answer I needed, I made a bunch of changes that got my code working. Some of the important ones that might have helped my cause are:



  1. Corrected http to https in my external host
  2. Used a REST Message call as opposed to directly passing api in setEndpoint
  3. Using new sn_ws.RESTMessageV2('<api_name>', 'POST') instead of new sn_ws.RESTMessageV2('<app_name>.<api_name>', 'POST')


Hope this helps others in the future


View solution in original post

2 REPLIES 2

Thanks aakashshah!



Your links were very useful and while they did not directly get me the answer I needed, I made a bunch of changes that got my code working. Some of the important ones that might have helped my cause are:



  1. Corrected http to https in my external host
  2. Used a REST Message call as opposed to directly passing api in setEndpoint
  3. Using new sn_ws.RESTMessageV2('<api_name>', 'POST') instead of new sn_ws.RESTMessageV2('<app_name>.<api_name>', 'POST')


Hope this helps others in the future