java.net.SocketException:套接字失败:EACCES(权限被拒绝)

java.net.SocketException: socket failed: EACCES (Permission denied)

我已经搜索了所有解决方案并将其应用到我的项目中。但他们没有工作。我有此权限 denied.I 已将所有可能的权限放入清单文件。请告诉我我的项目有什么问题。

public static void getGetResponse() {
        InputStream inputStream = null;
        try {
            URL url = new URL("http://120.26.89.113:8080/common/qiniuToken");
            HttpURLConnection connection = (HttpURLConnection)url.openConnection();
            connection.setRequestMethod("GET");          
            String userPassword = "wehelper:***********";
            byte[] encodedBytes = Base64.encode(userPassword.getBytes(), 0);
            connection.setRequestProperty("Authorization", "Basic " + encodedBytes);
            connection.connect();
            int resCode = connection.getResponseCode();
            if (resCode == 200) {
                inputStream = connection.getInputStream();
            }

            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            StringBuilder out = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                out.append(line);
            }
            System.out.println(out.toString());//Prints the string content read from input stream
            Log.d("myApp",out.toString());
            reader.close();

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

和我的manifest.xml

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/MyMaterialTheme">
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Logcat:

W/System.err: java.net.SocketException: socket failed: EACCES (Permission denied)
W/System.err:     at libcore.io.IoBridge.socket(IoBridge.java:619)
W/System.err:     at java.net.PlainSocketImpl.create(PlainSocketImpl.java:198)
W/System.err:     at java.net.Socket.checkOpenAndCreate(Socket.java:689)
W/System.err:     at java.net.Socket.setSoTimeout(Socket.java:543)
W/System.err:     at com.android.okhttp.internal.http.SocketConnector.connectRawSocket(SocketConnector.java:433)
W/System.err:     at com.android.okhttp.internal.http.SocketConnector.connectCleartext(SocketConnector.java:105)
W/System.err:     at com.android.okhttp.Connection.connect(Connection.java:1331)
W/System.err:     at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:1410)
W/System.err:     at com.android.okhttp.OkHttpClient.connectAndSetOwner(OkHttpClient.java:128)
W/System.err:     at com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:466)
W/System.err:     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:447)
W/System.err:     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:353)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:468)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:118)
W/System.err:     at com.donghuaxue.spoonhunt.HttpClient.getGetResponse(HttpClient.java:44)
W/System.err:     at com.donghuaxue.spoonhunt.MainActivity.onCreate(MainActivity.java:42)
W/System.err:     at android.app.Activity.performCreate(Activity.java:6876)
W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
W/System.err:     at android.app.ActivityThread.access00(ActivityThread.java:222)
W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err:     at android.os.Looper.loop(Looper.java:158)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7229)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
W/System.err: Caused by: android.system.ErrnoException: socket failed: EACCES (Permission denied)
W/System.err:     at libcore.io.Posix.socket(Native Method)
W/System.err:     at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:282)
W/System.err:     at libcore.io.IoBridge.socket(IoBridge.java:604)
W/System.err:   ... 27 more

您的 <uses-permission> 元素位置错误。它们需要在 <application> 元素之外,作为根 <manifest> 元素的直接子元素:

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/MyMaterialTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>