how can I code the following curl commands to java,
curl -k --request POST "<hostname>/login" -d IDToken1="user" -d IDToken2="password" --cookie-jar cookie.txt
curl -w "%{http_code}" -G -s --insecure --request GET --cookie cookie.txt '<requested-url>'
I am able to perform post but not sure how to keep the response in cookie and then, how can I use cookies in HTTP get request.
while doing post what I am trying is
public void httpPostRequest() throws Exception{
URL url = new URL("url/login");
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
String userCredentials = "user"+":"+"password";
String basicAuth = "Basic " + new String(new Base64().encode(userCredentials.getBytes()));
urlConnection.setRequestProperty ("Authorization", basicAuth);
try {
urlConnection.setRequestMethod("POST");
} catch (ProtocolException e) {
e.printStackTrace();
}
cookies = urlConnection.getHeaderFields().get("Set-Cookie");
System.out.println("these are cookies"+cookies);
}
Am I doing it wrong because cookies list is empty