Skip to main content

This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.

Support Article

REST POST method is not setting Content-Type and Boundary



User is using Pega 7.2. They have an use case where-in they are trying to send an email body (JSON) using Connect-REST POST method and the attachment present in the same email as multi-part attachment using the same Connect-REST call which also sends the email body as JSON POST request. In this use case, the below issues are observed:

1. Content-Type for the POST Request body (PostData) is always "text/plain" even though Content-Type is explicitly set to "application/json" in the POST method header within Connect-REST rule.

2. Boundary is not present in the generated request header although the attachment and post body are separated by Boundary. The header looks like below:

POST /prweb/PRRestService/RestSvcPkg/FetchPolicyDetails/FetchPolicyDetails HTTP/1.1
Content-Type: application/json
Content-Length: 791141
Host: xxxxxx:xxxx
Connection: Keep-Alive

It should be generated as below when sending multipart attachment:

POST /prweb/PRRestService/RestSvcPkg/FetchPolicyDetails/FetchPolicyDetails HTTP/1.1
Content-Length: 790916
Content-Type: multipart/form-data; boundary=mKKpgdXUNh7A8YDr_Xp69LvWsWnOCtK
Host: xxxxxx:xxxx
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.5)

Error Messages

Not Applicable

Steps to Reproduce

  1. Create a Connect-REST call.
  2. In an activity, set pyAttachNames, pyAttachValues, pyAttachTypes on pyRequestAttachmentPage to send the attachment as multi part attachment.
  3. Set the Value of a Property (to be used in POST method body) to a String.
  4. Map the Property as Message Data with Map From set as JSON within the Connect-REST POST Request.
  5. Set Content-Type in of POST Request Header as "application/json".
  6. Invoke the activity to execute the Connect-REST call.

Root Cause

A defect in Pegasystems’ code or rules is identified as root cause.


Perform the following local-change: 
  1. Save pyInvokeRESTConnector activity to the application ruleset.
  2. In Java step-6 of the pyInvokeRESTConnector activity, replace the below code:
if(messageData != null && !"".equals(messageData)) 

((com.pega.apache.http.entity.mime.MultipartEntity) entity).addPart("PostData", new com.pega.apache.http.entity.mime.content.StringBody(messageData)); 

with : 

if(messageData != null && !"".equals(messageData)) 

if(paramMapFrom.equalsIgnoreCase("json")) { 
((com.pega.apache.http.entity.mime.MultipartEntity) entity).addPart("PostData", new com.pega.apache.http.entity.mime.content.StringBody(messageData, "application/json", null)); 

else { 
((com.pega.apache.http.entity.mime.MultipartEntity) entity).addPart("PostData", new com.pega.apache.http.entity.mime.content.StringBody(messageData)); 

Suggest Edit

Published August 24, 2018 - Updated October 8, 2020

Did you find this content helpful? Yes No

100% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

We'd prefer it if you saw us at our best.

Pega Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice
Contact us