i need to convert the following curl command into java command.
curl https://api.linkedin.com/v2/me -H "Authorization: Bearer xxx"
I writed this code:
public static void main(String[] args) throws MalformedURLException, IOException{
HttpURLConnection con = (HttpURLConnection) new URL("https://api.linkedin.com/v2/me").openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Authorization", "Bearer xxx");
con.setDoOutput(true);
con.setDoInput(true);
con.getOutputStream().write("LOGIN".getBytes("UTF-8"));
con.getInputStream();
}
but I get an error:
Exception in thread "main" java.io.FileNotFoundException: https://api.linkedin.com/v2/me
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1915)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1515)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250)
at testiamo.main(testiamo.java:18)
HttpsURLConnection con = (HttpsURLConnection)new URL("https://api.linkedin.com/v2/me").openConnection();(import javax.net.ssl.HttpsURLConnection;)