错误500 HttpURLConnection,但在localhost中可以

时间:2019-11-25 14:16:59

标签: java post httpurlconnection

我试图用下面的HttpURLConnection调用在JAVA中实现的终结点。如果我将路径作为我的应用程序在localhost中运行,则一切正常。 但是,当此应用程序发布到服务器(Oracle Weblogic)中时,出现错误:

  
    

java.io.IOException:服务器返回的HTTP响应代码:500用于URL:路径         在sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1894)         在sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)

  

此错误在带有**的行的下面的块中引发

        try {
            URL url = new URL(path);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
            conn.setConnectTimeout(10000);
            conn.setReadTimeout(10000);
            conn.setRequestProperty("Accept", "*/*");
            conn.setRequestProperty("Accept-Encoding", "gzip, deflate");
            conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
            conn.setRequestProperty("Content-Language", "en-US");
            conn.setUseCaches(false);
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Connection", "close");
            OutputStream os = conn.getOutputStream();
            os.write(new Gson().toJson(debtAccountList).getBytes("UTF-8"));
            os.flush();
            ***InputStream in = new BufferedInputStream(conn.getInputStream());***

            System.out.println(in.toString());
            in.close();
            os.close();
            conn.disconnect();
        }

是什么使它在localhost上有效但在已部署的应用程序中无效?

0 个答案:

没有答案