I want to send a POST request with the below curl command:
curl -d @request.json --header "Content-Type: application/json" https://www.googleapis.com/qpxExpress/v1/trips/search?key=my_API_key
I have created a JSON file with name request.json using the below code:
public void CreateJSONFile(View view) throws IOException, JSONException {
JSONObject request_hdr = new JSONObject();
JSONObject request = new JSONObject();
JSONArray slice = new JSONArray();
JSONObject data = new JSONObject();
request.put("solutions", 20);
request.put("refundable", "false");
JSONObject addl_info = new JSONObject();
addl_info.put("adultCount",Num_Adult);
addl_info.put("infantInLapCount",Num_Infant);
addl_info.put("infantInSeatCount", 0);
addl_info.put("childCount",0);
addl_info.put("seniorCount", 0);
request.put("passengers",addl_info);
data.put("origin",Origin);
data.put("destination",Destination);
data.put("date", Start_Date);
slice.put(data);
request.put("slice",slice);
request_hdr.put("request",request);
text = request_hdr.toString();
FileOutputStream fileOutputStream = openFileOutput("request.json", MODE_PRIVATE);
fileOutputStream.write(text.getBytes());
fileOutputStream.close();
}
Now how do I trigger the POST request with the curl command using the JSON file created. I have found couple of examples which uses Name-Value Pairs or JSON Objects. How do I use a JSON file instead of that. Please help me out.
Thanks in advance!