Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从java打开URL_Java_Url - Fatal编程技术网

从java打开URL

从java打开URL,java,url,Java,Url,我们正在为bigquery编写一个开源jdbc驱动程序,遇到了以下问题: 我们想将Oauth 2作为已安装的应用程序来授权我们的驱动程序。在WindowsXP、Windows7x64、Windows7x64+RDP上工作正常。但在windows server 2008 R2+RDP的测试台上,它失败了 基本上,我们打开一个web浏览器,他登录,我们捕获回复,并对用户进行身份验证 以下是url打开的代码: private static void browse(String url) {

我们正在为bigquery编写一个开源jdbc驱动程序,遇到了以下问题:

我们想将Oauth 2作为已安装的应用程序来授权我们的驱动程序。在WindowsXP、Windows7x64、Windows7x64+RDP上工作正常。但在windows server 2008 R2+RDP的测试台上,它失败了

基本上,我们打开一个web浏览器,他登录,我们捕获回复,并对用户进行身份验证

以下是url打开的代码:

    private static void browse(String url) {
    // first try the Java Desktop
    logger.debug("First try the Java Desktop");
    if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Action.BROWSE))
            try {
                desktop.browse(URI.create(url));
                return;
            } catch (IOException e) {
                // handled below
            }
    }
    // Next try rundll32 (only works on Windows)
    logger.debug("Try the rundll32");
    try {
        Runtime.getRuntime().exec(
                "rundll32 url.dll,FileProtocolHandler " + url);
        return;
    } catch (IOException e) {
        // handled below
    }
    // Next try browsers
    logger.debug("Try with browsers");
    BareBonesBrowserLaunch.openURL(url);
}
我发现:BareBonesBrowserLaunch不会打开链接,FileProtocolHandler也不会打开

URL长度有点小于250个字符


任何帮助都将不胜感激

使用
java.net.HttpURLConnection

URL myURL = new URL("http://example.com/");
    URLConnection myURLConnection = myURL.openConnection();
    myURLConnection.connect();

使用
java.net.HttpURLConnection

URL myURL = new URL("http://example.com/");
    URLConnection myURLConnection = myURL.openConnection();
    myURLConnection.connect();

这里有一个不同角度的建议。(不确定这是否是您的选择)

您试图解决的问题是使用Oauth 2和身份验证机制。而不是打开捕获其响应的浏览器。现在已经有这样的库,它们纯粹用java来实现这一点


这是一位你可以参考的官员

这里有一个不同角度的建议。(不确定这是否是您的选择)

您试图解决的问题是使用Oauth 2和身份验证机制。而不是打开捕获其响应的浏览器。现在已经有这样的库,它们纯粹用java来实现这一点


这是一位你可以参考的官员

基本上听起来不错,但如果您想使用特定浏览器打开(如果系统中有多个浏览器),这里有另一种方法

String url=“http:/devmain.blogspot.com/”;
String[]浏览器={“firefox”、“opera”、“mozilla”、“netscape”};//常用浏览器名称
字符串浏览器=null;
对于(int count=0;count

此处有更多详细信息:

基本上听起来不错,但如果您想使用特定浏览器打开(如果系统中有多个浏览器),这里有另一种方法

String url=“http:/devmain.blogspot.com/”;
String[]浏览器={“firefox”、“opera”、“mozilla”、“netscape”};//常用浏览器名称
字符串浏览器=null;
对于(int count=0;count

此处的更多详细信息:

运行时没有任何错误,但仍无法打开任何带有url的浏览器。运行时没有任何错误,但仍无法打开任何带有url的浏览器。