I have made a GUI in Java Swing and want to hit an API (POST method) On a button click like
I have to send a JSON object as a request parameter along with the header i.e (Headers["custom-Header"] == "AXYZ") I have converted my Strings to a JSON object like
{"machineKey":"","serialNumber":"","name":"","mobile":"","productKey":"","email":""}
What I simply did is
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == Submit)
{
dispose();
new Otp().setVisible(true);
}
else
{
name.setText("");
email.setText("");
mobile.setText("");
machineKey.setText("");
productKey.setText("");
serialNumber.setText("");
}
String Sname= name.getText();
String Semail= email.getText();
String Smobile= mobile.getText();
String SmachineKey= machineKey.getText();
String SproductKey= productKey.getText();
String SserialNumber= serialNumber.getText();
JSONObject abc=prepareReqJsonObj(Sname,Semail,Smobile,SmachineKey,SproductKey,SserialNumber);
System.out.println(abc);
}
Now, how can I make request directly from my GUI button to Hit the API, what way I can achieve this and get a response.
Thanks for your help in advance :)