Java url 执行抛出权限被拒绝错误

发布于 2024-11-18 16:58:09 字数 776 浏览 3 评论 0原文

以下代码会抛出permision Denied Expected

String strurl = "https://login.yahoo.com/WSLogin/V1/get_auth_token?&login=name&passwd=passwd&oauth_consumer_key=dj0yJmk9WnhsVVZvSDhkYTVpJmQ9WVdrOWMwRlVZV0p2TkRnbWNHbzlNVFE0TURJek5qVTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0yNg";
URL url;
try
  {
    url = new URL(strurl);
    HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
    System.out.println(urlConnection.getInputStream());
  }
catch (MalformedURLException e)
  {
            // TODO Auto-generated catch block
     e.printStackTrace();
  }
catch (IOException e)
  {
   // TODO Auto-generated catch block
      e.printStackTrace();
  }

如果我直接在浏览器中使用该 URL,我会得到正确的响应,在这种情况下会显示请求令牌。这里有什么问题;如果调用还有其他方法吗?

The following code throws permision denied expection

String strurl = "https://login.yahoo.com/WSLogin/V1/get_auth_token?&login=name&passwd=passwd&oauth_consumer_key=dj0yJmk9WnhsVVZvSDhkYTVpJmQ9WVdrOWMwRlVZV0p2TkRnbWNHbzlNVFE0TURJek5qVTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0yNg";
URL url;
try
  {
    url = new URL(strurl);
    HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
    System.out.println(urlConnection.getInputStream());
  }
catch (MalformedURLException e)
  {
            // TODO Auto-generated catch block
     e.printStackTrace();
  }
catch (IOException e)
  {
   // TODO Auto-generated catch block
      e.printStackTrace();
  }

If I use the URL directly in the browser I get a proper response in this case a request token is displayed. What is the problem here; is there any other way if calling it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初心 2024-11-25 16:58:09

我没有 Android 开发经验,但是您不需要在清单 xml 中定义访问网络的权限吗? (我想你是通过你的标签从 Android 执行该代码的)

I am not experienced with Android development but don't you have to define permissions in manifest xml to access network? (I suppose that you execute that code from Android by your tag)

带刺的爱情 2024-11-25 16:58:09

如果没有,则需要在 AndroidManifest.xml 中添加 INTERNET 权限:

<uses-permission
        android:name="android.permission.INTERNET" />

You need to add INTERNET permission to the AndroidManifest.xml, if you don't have it:

<uses-permission
        android:name="android.permission.INTERNET" />
相思碎 2024-11-25 16:58:09

放入 AndroidManifest.xml 中,就在 Manifest 内标签。

Put <uses-permission android:name="android.permission.INTERNET"></uses-permission> in your AndroidManifest.xml, just within the Manifest tags.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文