How to fix 'Cannot cast object with class MultipartFormEntity to HttpEntity' erro in Groovy

646 views Asked by At

I'm trying to Post RestAPI with form-data content in Groovy.

MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addPart("nationality", new StringBody("0082410999"));

HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost postRequest = new HttpPost();

//////An error occurs on this line
postRequest.setEntity(multipartEntity.build())

Please help about this Error :

Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'org.apache.http.entity.mime.MultipartFormEntity@ee2abaf' with class 'org.apache.http.entity.mime.MultipartFormEntity' to class 'org.apache.http.HttpEntity'

Thanks a lot, Ali

0

There are 0 answers