无法从Android Studio中的网站获取数据

时间:2019-08-22 17:27:48

标签: java android android-studio

我无法从该网站“ http://www.posh24.se/kandisar”获得html代码。但是,当我尝试从“ google.com”下载数据时,它可以工作吗?我该如何解决?也许我必须添加一些权限?

private static class DownloadContentStars extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... strings) {

            URL url = null;
            HttpURLConnection urlConnection = null;
            StringBuilder result = new StringBuilder();
            try {
                url = new URL(strings[0]);
                urlConnection = (HttpURLConnection) url.openConnection();
                InputStream in = urlConnection.getInputStream();
                InputStreamReader inputStreamReader = new InputStreamReader(in);
                BufferedReader reader = new BufferedReader(inputStreamReader);
                String line = reader.readLine();
                while (line != null) {
                    result.append(line);
                    line = reader.readLine();
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (urlConnection != null) {
                    urlConnection.disconnect();
                }
            }

            return result.toString();
        }
    }

在这里您可以看到我的日志 我在Xiomi Redmi Note 7上开始编程 我想我必须添加一些权限,但是我不知道哪个

2019-08-22 20:46:51.827 8668-8668/com.example.guessstar I/ample.guesssta: Late-enabling -Xcheck:jni
2019-08-22 20:46:52.171 8668-8668/com.example.guessstar I/Perf: Connecting to perf service.
2019-08-22 20:46:52.412 8668-8668/com.example.guessstar W/ample.guesssta: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2019-08-22 20:46:52.414 8668-8668/com.example.guessstar W/ample.guesssta: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2019-08-22 20:46:52.543 8668-8746/com.example.guessstar I/DpmTcmClient: RegisterTcmMonitor from: com.android.okhttp.TcmIdleTimerMonitor
2019-08-22 20:46:52.552 8668-8746/com.example.guessstar D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2019-08-22 20:46:52.555 8668-8746/com.example.guessstar W/System.err: java.io.IOException: Cleartext HTTP traffic to www.posh24.se not permitted
2019-08-22 20:46:52.555 8668-8746/com.example.guessstar W/System.err:     at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:115)
2019-08-22 20:46:52.555 8668-8746/com.example.guessstar W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:458)
2019-08-22 20:46:52.555 8668-8746/com.example.guessstar W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:407)
2019-08-22 20:46:52.555 8668-8746/com.example.guessstar W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:244)
2019-08-22 20:46:52.556 8668-8746/com.example.guessstar W/System.err:     at com.example.guessstar.MainActivity$DownloadContentStars.doInBackground(MainActivity.java:56)
2019-08-22 20:46:52.556 8668-8746/com.example.guessstar W/System.err:     at com.example.guessstar.MainActivity$DownloadContentStars.doInBackground(MainActivity.java:46)
2019-08-22 20:46:52.556 8668-8746/com.example.guessstar W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:333)
2019-08-22 20:46:52.556 8668-8746/com.example.guessstar W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2019-08-22 20:46:52.556 8668-8746/com.example.guessstar W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
2019-08-22 20:46:52.556 8668-8746/com.example.guessstar W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2019-08-22 20:46:52.556 8668-8746/com.example.guessstar W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2019-08-22 20:46:52.556 8668-8746/com.example.guessstar W/System.err:     at java.lang.Thread.run(Thread.java:764)
2019-08-22 20:46:52.641 8668-8749/com.example.guessstar I/Adreno: QUALCOMM build                   : cf57c9c, I1cb5c4d1cc
    Build Date                       : 09/23/18
    OpenGL ES Shader Compiler Version: EV031.25.03.01
    Local Branch                     : 
    Remote Branch                    : 
    Remote Branch                    : 
    Reconstruct Branch               : 
2019-08-22 20:46:52.641 8668-8749/com.example.guessstar I/Adreno: Build Config                     : S L 6.0.7 AArch64
2019-08-22 20:46:52.646 8668-8749/com.example.guessstar I/Adreno: PFP: 0x005ff112, ME: 0x005ff066
2019-08-22 20:46:52.650 8668-8749/com.example.guessstar I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2019-08-22 20:46:52.650 8668-8749/com.example.guessstar I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2019-08-22 20:46:52.651 8668-8749/com.example.guessstar I/OpenGLRenderer: Initialized EGL, version 1.4
2019-08-22 20:46:52.651 8668-8749/com.example.guessstar D/OpenGLRenderer: Swap behavior 2
2019-08-22 20:47:00.094 8668-8697/com.example.guessstar I/ample.guesssta: ProcessProfilingInfo new_methods=942 is saved saved_to_disk=1 resolve_classes_delay=8000

2 个答案:

答案 0 :(得分:0)

我找到了解决方法:您只需添加以下代码行:android:usesCleartextTraffic="true" 到您的AndroidManifest.xml

<application
...
android:usesCleartextTraffic="true"
...>

希望这些信息将来对您有所帮助。

答案 1 :(得分:0)

该网站现已关闭。是别人买的。 您仍然可以在任何其他网站(例如福布斯)上找到名人名单。