Skip to content
Advertisement

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": "https://graph.microsoft.com/v1.0/groups/xyz/members"n"
        + "    }";
    StringEntity entity = new StringEntity(json);
    request.setEntity(entity);

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement