String ret = null; try { URL url = new URL(requrl); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); httpConn.setConnectTimeout(30000); httpConn.setReadTimeout(30000); httpConn.setDoOutput(true); httpConn.setDoInput(true); httpConn.setRequestMethod("POST"); DataOutputStream out = new DataOutputStream(httpConn.getOutputStream()); out.write(paras.getBytes("UTF-8")); out.flush(); out.close(); InputStream stream = httpConn.getInputStream(); DataInputStream in = new DataInputStream(stream); byte[] bin = null; byte[] inc = new byte[1024]; int datelength = 0; int insize = 0; while ((insize = in.read(inc)) != -1) { int oldlength = datelength; datelength += insize; byte[] oldbin = new byte[datelength]; for (int i = 0; i < oldlength; i++) oldbin[i] = bin[i]; for (int i = oldlength; i < datelength; i++) oldbin[i] = inc[i - oldlength]; bin = oldbin; } ret = new String(bin, "UTF8"); in.close(); System.out.println("ret is: " + ret); } catch (Exception ex) { ex.printStackTrace(); } return ret;
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-16 13:27:32