Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make post curl request in java

Tags:

This is my curl request.

curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' 
--header 'Accept: application/json' --header 'apikey: xxxx' -d 
'name=abcd&[email protected]&id=abc' 
'https://api.gupshup.io/appsdk/api/components/adduser'

Can anybody help me, how to send it using java servlet?

like image 434
Irshad Qureshi Avatar asked Apr 07 '16 11:04

Irshad Qureshi


1 Answers

If I were you I would use DavidWebb a lightweight Java HTTP-Client for calling JSON REST-Services and proceed as next:

Webb webb = Webb.create();
JSONObject result = webb
    .post("https://api.gupshup.io/appsdk/api/components/adduser")
    .header("Content-Type", "application/x-www-form-urlencoded")
    .header("apikey", "xxxx")
    .body("name=abcd&[email protected]&id=abc")
    .asJsonObject()
    .getBody();
like image 167
Nicolas Filotto Avatar answered Sep 28 '22 02:09

Nicolas Filotto