private int send(String URLHost, String URLPort, String LoginID, String LoginPWD, String uid, String MsgBody, String wapurl,Map otherMap){ String strResult = "999"; try{ // http地址 String httpUrl = new StringBuffer("http://").append(URLHost).append(":").append(URLPort).append(this.context) .toString() ; // System.out.println("=======begin===mochasoft=message==="+httpUrl); HttpParams paramsw = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(paramsw, 5 * 1000); //HttpPost连接对象 HttpPost httpRequest = new HttpPost(httpUrl); //使用NameValuePair来保存要传递的Post参数 List<NameValuePair> params = new ArrayList<NameValuePair>(); //添加要传递的参数 params.add(new BasicNameValuePair("LoginID", LoginID)); params.add(new BasicNameValuePair("LoginPWD", LoginPWD)); params.add(new BasicNameValuePair("MsgBody", MsgBody)); params.add(new BasicNameValuePair("uid", uid)); params.add(new BasicNameValuePair("appBusiNum", "")); params.add(new BasicNameValuePair("SmsType", "0")); params.add(new BasicNameValuePair("sendUid", otherMap.get("sendUid")==null?"":(String)otherMap.get("sendUid"))); params.add(new BasicNameValuePair("sendUserName", otherMap.get("sendUserName")==null?"":(String)otherMap.get("sendUserName"))); params.add(new BasicNameValuePair("sendPhone", otherMap.get("sendPhone")==null?"":(String)otherMap.get("sendPhone"))); params.add(new BasicNameValuePair("extend1", otherMap.get("extend1")==null?"":(String)otherMap.get("extend1"))); params.add(new BasicNameValuePair("extend2", otherMap.get("extend2")==null?"":(String)otherMap.get("extend2"))); params.add(new BasicNameValuePair("extend3", otherMap.get("extend3")==null?"":(String)otherMap.get("extend3"))); //设置字符集 HttpEntity httpentity = new UrlEncodedFormEntity(params, "utf-8"); //请求httpRequest httpRequest.setEntity(httpentity); //取得默认的HttpClient HttpClient httpclient = new DefaultHttpClient(paramsw); // HttpClient httpclient =HttpConnectionManager.getHttpClient(); //取得HttpResponse // System.out.println("======================="+httpclient.); HttpResponse httpResponse = httpclient.execute(httpRequest); //HttpStatus.SC_OK表示连接成功 System.out.println("============================"+httpResponse.getStatusLine().getStatusCode()); if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { //取得返回的字符串 strResult = EntityUtils.toString(httpResponse.getEntity()); System.out.println("请求成功"+strResult); } else { System.out.println("请求失败"); } }catch(Exception e){ e.printStackTrace(); } return Integer.parseInt(strResult); }
有什么优化的方法??
有没具体的实例参考下 。 ######oschina上就有:http同步异步的对比 http://my.oschina.net/yilian/blog/185990######是哪边响应不过来?请求方还是服务方?###### 服务端 现在想客户端和服务端都做优化 想知道客户端需要怎么优化######
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。