1

The same question asked here but I want to make a request with following structure.

"method": "post",

"url": parserApiUrl,

"data": {

"url": s3BaseUrl + imageKey

},

"headers": {

"x-api-key": "sdsdasdwdw"

}
Arul
  • 1,031
  • 13
  • 23
  • Please have a look on how to make a network request. https://www.androidhive.info/2012/01/android-json-parsing-tutorial/ – Aris Panayiotou Jan 03 '18 at 09:38
  • on that tutorial he used to get result as json, here i want to send "data:{file:value}" and "headers:{xapi:value}" to server – Arul Jan 03 '18 at 11:27

1 Answers1

7

I Found a solution for this by this steps

urlConnection = (HttpURLConnection) url
                        .openConnection();
                urlConnection.setDoOutput(true);
                urlConnection.setRequestMethod("POST");
                urlConnection.setRequestProperty("Content-Type", "application/json");
                urlConnection.setRequestProperty("x-api-key", x_api);
                urlConnection.setRequestProperty("Accept", "application/json");

                String datajson =  "{\"file\": \""+imageString.trim()+"\"}";
                Log.e("data","json:"+datajson);

                OutputStream os = urlConnection.getOutputStream();
                os.write(datajson.getBytes("UTF-8"));
                os.close();
Arul
  • 1,031
  • 13
  • 23