使用connect命令进行HTTP连接

时间:2019-04-12 11:15:04

标签: android http url connection httpurlconnection

http连接错误。在下面的代码中,conn.connect()中存在错误;

在android,manifest.xml中我已经

    android:usesCleartextTraffic="true"

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

    URL u = new URL(url);
    HttpURLConnection conn = (HttpURLConnection) u.openConnection();
    conn.setRequestMethod("GET");
    conn.setDoOutput(true);
    conn.setDoInput(true);
    conn.connect();

0 个答案:

没有答案