I am writing a program which would connect to a Https url and will authenticate using username and password and the send a Post request Query and get output in Json. I have been stuck up in authentication part and sending Post request. Please help me with it. how and where do I add username password?
Also I need to add headers=("application/json")
public static void main(String a[]) throws IOException{
URL url = new URL("https://url");
URLConnection connection = url.openConnection();
connection.connect();
HttpsURLConnection httpsConnection = (HttpsURLConnection) connection;
httpsConnection.setAllowUserInteraction(true);
StringEntity input = new StringEntity("{'query': 'select i.interfaceid, i.node.caption as node_name, i.node.nodeid as nodeid, i.caption as interface_name, i.interfacelastchange, i.operstatus, i.adminstatus from orion.npm.interfaces i where (i.unmanaged = 0 and i.status <> 1) and daydiff(i.interfacelastchange, getdate()) >= 90 and (i.operstatus > 1 or i.adminstatus > 1)', 'parameters': ''}");
request.setRequestMethod("POST");
OutputStream post = request.getOutputStream();
input.writeTo(post);
post.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream()));
String inputLine, response = "";
while ((inputLine = in.readLine()) != null) {
response += inputLine;
}
post.close();
}