Skip to content

HTTP POST with request body

For this request, I am trying to set the entity, however when I do request.setEntity, it says required type HttpEntity, on upcasting it to HttpEntity as request.setEntity((HttpEntity) entity) it still gives me exception.

final HttpPost request = new HttpPost(url);
    String json = "{n"
        + "      "id": "1",n"
        + "      "method": "GET",n"
        + "      "url": ""n"
        + "    }";
    StringEntity entity = new StringEntity(json);


I was using “com.signalfx.shaded.apache.http.entity.StringEntity” instead of “import org.apache.http.entity.StringEntity” which was causing the issue.