我收到此错误“读取输入后无法写入输出”,发送请求信息

时间:2019-05-16 15:23:38

标签: java post request

发送此请求,我在dataOutputStream中有“读取输入后无法写入输出”的错误。

URL url = new URL(Dir);
String userString = (String)getProperties().get("USER"); String PassInt =  getProperties().get("PASSWORD_PROPERTY").toString();

String usernameColonPassword = userString + ":" + PassInt;
String encoding =  Base64.getEncoder().encodeToString((usernameColonPassword).getBytes("UTF-8"));

HttpURLConnection connect = (HttpURLConnection)  url.openConnection();
connect.setRequestMethod("POST");
connect.setDoInput(true);
connect.setDoOutput(true);
connect.setRequestProperty("Authorization","Basic " + encoding);//+ encoding);
connect.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
connect.getHeaderField("x-csrf-token");
connect.getResponseMessage();

try (DataOutputStream dataOutputStream = new DataOutputStream(connect.getOutputStream())){
    CDBSession session = CDBSessionFactory.instance.createSession();
    EntityManager em = session.getEM();
    Query q = em.createNativeQuery("SELECT * FROM  CEODO_LOC_DO_SEC");

    @SuppressWarnings("unchecked")
    java.util.List<Object[]> results = q.getResultList(); 

    for (int i = 0; i < results.size(); i++) {
        byte[] out = results.get(i).toString().getBytes();
        dataOutputStream.writeBytes(results.get(i).toString());
        dataOutputStream.flush();
        dataOutputStream.close();
    }
}

错误:

  

“读取输入后无法写入输出”

0 个答案:

没有答案