简体   繁体   中英

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);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM