httpurlconnection在本地可以很好地处理所有URL,但在服务器上却不行

cigdeys3  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(279)

我一直在尝试获取一些网址的http状态码它在本地可以正常工作,但在服务器上不行

try {
            long start = System.currentTimeMillis();

            String url = "https://e2e.ti.com/blogs_/b/industrial_strength/archive/2016/02/17/trends-in-building-automation-energy-efficiency?HQS=hpa-mhrs-ssc-sensingoverview-asset-blog-null-wwe&DCM=yes";
            URL u;
            u = new URL(url);
            HttpsURLConnection con = (HttpsURLConnection) u.openConnection();
            con.setRequestProperty("User-Agent", "application/json");
            con.setRequestProperty("Accept", "application/json; charset=utf-8");
            con.setRequestMethod("GET");
            con.setDoOutput(true);
            con.setDoInput(true);
            con.setUseCaches(false);
            con.setAllowUserInteraction(false);
            con.setConnectTimeout(15000);
            System.out.println(con.getResponseCode());
            System.out.println("Done in " + (System.currentTimeMillis() - start));

        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }

这个网址在本地将得到200,但在服务器上它将一无所获

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题