httpclient apache 开源http框架
post 请求
HttpClient client = new DefaultHttpClient();HttpPost httpPost = new HttpPost(url + "ConnDBfind");List<Object[]> list = null;List<NameValuePair> params = new ArrayList<NameValuePair>();params.add(new BasicNameValuePair("sql", sql));httpPost.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 10 * 1000);Gson gson = new Gson();try {httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));HttpResponse response = client.execute(httpPost);if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {String result = EntityUtils.toString(response.getEntity(),"utf-8");list = gson.fromJson(result, new TypeToken<List<Object[]>>() {}.getType());for(int i=0;i<list.size();i++){for(int j=0;j<list.get(i).length;j++){try {list.get(i)[j].toString();} catch (Exception e) {list.get(i)[j]=0;}}}}} catch (Exception e) {list = null;}return list;
get 请求
附上:

