标签:android style blog http color io os ar java
============问题描述============
URL url = null; HttpURLConnection conn = null; String result = ""; try { String sParam = "&m=" + methodName; if (vector != null) { for (int i = 0; i < vector.size(); i++) { sParam += "&p" + String.valueOf(i) + "=" + vector.elementAt(i).toString(); } } byte[] data = sParam.getBytes(); url = new URL(realURL.replace("xx.mobile", methodName+".mobile")); conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(CONNECT_TIMEOUT); conn.setReadTimeout(READ_TIMEOUT); conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestMethod(METHOD_POST); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setRequestProperty("Content-Length", String.valueOf(data.length)); conn.setRequestProperty("Charset", "utf-8"); conn.setUseCaches(false); OutputStream outStream = conn.getOutputStream(); outStream.write(data); outStream.flush(); outStream.close(); if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) // ResponseCode:200 { InputStream inStream = conn.getInputStream(); //int contentLen = conn.getContentLength(); result = readInputStream(inStream,1024); inStream.close(); } else { result = "500"; //server error } } catch (ConnectTimeoutException e) { // TODO: handle exception CommonData.Log("ConnectTimeoutException"); throw new MyException(HTTP_RESULT_CONNECT_TIMEOUT); } catch (SocketTimeoutException e) { // TODO: handle exception CommonData.Log("SocketTimeoutException"); throw new MyException(HTTP_RESULT_READ_TIMEOUT); } catch (Exception e) { // TODO: handle exception CommonData.Log(e.getLocalizedMessage()); throw new MyException(HTTP_RESULT_EXCEPTION); } finally { conn.disconnect(); }
============解决方案1============
============解决方案2============
============解决方案3============
============解决方案4============
============解决方案5============
============解决方案6============
连接超时和读取超时时间会不会不一致?
这2者不一致有关系吗?
标签:android style blog http color io os ar java
原文地址:http://www.cnblogs.com/liangxieliang56/p/4038870.html