I have a curl POST request to do in java and i want to convert it to a simple HTTP request with a json file as body content, or to execute it without the conversion.
I tried to convert the request as a simple HTTP POST but it didn't work.
FileWriter file2 = new FileWriter("/home/oairan/NetBeansProjects/test1/src/post_slice.json");
file2.write(json.toString());
file2.close();
URL obj = new URL("http://127.0.0.1:9999/slice/enb/-1 --data-binary @/home/oairan/NetBeansProjects/test1/src/post_slice.json");
HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json"); con.setRequestProperty("Method", "POST");
if(con.getResponseCode() == HttpURLConnection.HTTP_OK)
{
//some code here
}
The original curl request is:
curl -X POST http://127.0.0.1:9999/ue_slice_assoc/enb/-1 --data-binary "@file2"
can i execute it without using the HTTP request? Thank you in advance.