POST request with curl command for android using a JSON file -
i want send post request 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 json file name request.json using 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 trigger post request curl command using json file created. have found couple of examples uses name-value pairs or json objects. how use json file instead of that. please me out.
thanks in advance!
Comments
Post a Comment