Java url 执行抛出权限被拒绝错误
以下代码会抛出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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我没有 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)
如果没有,则需要在 AndroidManifest.xml 中添加 INTERNET 权限:
You need to add INTERNET permission to the AndroidManifest.xml, if you don't have it:
将
放入 AndroidManifest.xml 中,就在Manifest
内标签。Put
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
in your AndroidManifest.xml, just within theManifest
tags.