showing results for - "java post request json"
Marta
06 Jul 2019
1Here is what you need to do:
2
3Get the Apache HttpClient, this would enable you to make the required request
4Create an HttpPost request with it and add the header application/x-www-form-urlencoded
5Create a StringEntity that you will pass JSON to it
6Execute the call
7The code roughly looks like (you will still need to debug it and make it work):
8
9// @Deprecated HttpClient httpClient = new DefaultHttpClient();
10HttpClient httpClient = HttpClientBuilder.create().build();
11try {
12    HttpPost request = new HttpPost("http://yoururl");
13    StringEntity params = new StringEntity("details={\"name\":\"xyz\",\"age\":\"20\"} ");
14    request.addHeader("content-type", "application/x-www-form-urlencoded");
15    request.setEntity(params);
16    HttpResponse response = httpClient.execute(request);
17} catch (Exception ex) {
18} finally {
19    // @Deprecated httpClient.getConnectionManager().shutdown(); 
20}
queries leading to this page
send json data in post request in javapost request with json body javapost request json javaget request from post json javasend post with json javasend a json post response using javasend json object in post request javajava send post request with json body examplejava code to post json requestjava make post request with json bodysend json httppost javahttp client post java jsonjava post jsonjava http request post json with umlautjava send json in post requestjson post request javapost java jsonhow to construct a json object in java for post requestjava api to send json body in post requestjava get request body jsonjava send json requestjava post request json libraryjava send json postjava http request post jsonjava send http request with json bodyjava json postjava post request with json bodysend json data in post javasend json data in post request suing javajava json get from posthttp post json object request java with exampleread a json in post request javahow to get json data from post request in javajava http request post example with jsonjava post body jsonjava json post request examplejava 8 post jsonsend post json request javahow to send json data using http post request in javajava api json posthttp json post request javahit a post api in java and send a json to itjava post request wirh json objectmake a post request with json body javajson to java post apijava json get post request java http post request jsonpost method using json javasend json data in post request javaget json from post url response javajava get json post datapost json data in java and response objectjava post http request with jsonjava json body postjava json post from requestjava http post json objecthow to pass a json in a post request in javahow to send json object in post request in javajava api simple json postjava json post requestjava send post request with json body httpsjava post return jsonjava post json objectpost json data to rest api javapost java response to jsonjava request post with org jsonsend json in post request javapost json data in java and response object javajava post request json 2020java get json post java rest api post json examplejava rest post json examplejson post request example javahttp request post json javahow to post json data in javamake a post request with json javajava send post request with json bodyjava send simple json postjava post request jsonsendin json post request javajava post request jsonpost request json object to java objectjava send post requestpost json data javajava http post request with json bodyjava http post jsonsent json to java posthow to send json in request body in javapost request send 40json file javahttp post and get in java application 2fjsonsending json post request javapost request send json file javajava post request json