Opening an URL from java

后端 未结 3 738
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-03 16:16

we\'re writing an open-source jdbc driver for bigquery, and ran into the following problem:

We want to authorize our driver with Oauth 2 as an installed application.

相关标签:
3条回答
  • 2021-01-03 16:47

    Basically sounds good but here is another way if you want to open using specific browser (if more than one browser in the system)

    String url = "http:/devmain.blogspot.com/";
    String[] browsers = { "firefox", "opera", "mozilla", "netscape" }; // common browser names
    String browser = null;
    for (int count = 0; count < browsers.length && browser == null; count++)
      if (Runtime.getRuntime().exec(new String[] { "which", browsers[count] }).waitFor() == 0)
        browser = browsers[count]; // have found a browser
    Runtime.getRuntime().exec(new String[] { browser, url }) // open using a browser
    

    More details here: http://devmain.blogspot.com/2013/10/java-how-to-open-url-in-browser.html

    0 讨论(0)
  • 2021-01-03 16:56

    Here is a suggestion from a different perspective. (Not sure if this is an option to you)

    The problem that you are trying to solve is to use Oauth 2 and authentication mechanism. Instead of opening a browser capturing its response. There are already available libraries like Apache amber which do this purely in java.

    Here is an official Amber Example that you can refer to.

    0 讨论(0)
  • 2021-01-03 16:57

    Using java.net.HttpURLConnection

    URL myURL = new URL("http://example.com/");
        URLConnection myURLConnection = myURL.openConnection();
        myURLConnection.connect();
    
    0 讨论(0)
提交回复
热议问题