servlet 音讯转发ITeye - 娱乐之横扫全球

servlet 音讯转发ITeye

2019-01-12 06:53:09 | 作者: 环亚 | 标签: 选用,读取 | 浏览: 2126

conn.setUseCaches(false); conn.setRequestProperty("Content-type", "application/x-www-form-urlencoded;charset=UTF-8"); conn.setRequestMethod("POST"); conn.connect(); OutputStream raw = conn.getOutputStream(); OutputStream buf = new BufferedOutputStream(raw); OutputStreamWriter out = new OutputStreamWriter(buf, "UTF-8"); out.write(baos.toString()); out.flush(); out.close(); in = conn.getInputStream(); setCookie = conn.getHeaderField("Set-Cookie"); // 选用byte流读取 ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); byte[] bytes = new byte[1]; while (in.read(bytes) != -1) baos2.write(bytes); in.close(); String ouputData = new String(baos2.toByteArray()); System.out.println("ouputData = " + ouputData); resp.getWriter().write(ouputData); catch (Exception e) e.printStackTrace(); resp.getWriter().write("{\"errorCode\":401}"); finally if (in != null) in.close(); if (conn != null) conn.disconnect(); catch (IOException e) e.printStackTrace(); resp.getWriter().write("{\"errorCode\":401}");
版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表娱乐之横扫全球立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章