少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks
           
          京-pk發型不亂CEO<wuraolong@126.com>  23:33:00
            public String executeHttpRequest(String url, String requestContent,Log log) {
                  Log logHttp= log;  //logHttp對應的可能是開放平臺、酒店開放平臺、酒店
                  HttpClient client = new HttpClient();
                  PostMethod postMethod = new PostMethod(url);
                  try {
                      postMethod.setRequestEntity(new StringRequestEntity(requestContent, "text/xml; charset=" + charSet, charSet));
                      postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
                      postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, charSet);
                      postMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, soTimeOut);
                      int statusCode = client.executeMethod(postMethod);
                      BufferedReader in = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream(), charSet));
                      StringBuffer sb = new StringBuffer();
                      String line;
                      while ((line = in.readLine()) != null) {
                          sb.append(line);
                      }
                      in.close();
                      if (statusCode != HttpStatus.SC_OK) {
                          logHttp.error("Method:HttpClientUtil.executeHttpRequest---->請求返回狀態不為200,url:" + url + ",返回結果:" + sb.toString());
                          return "";
                      }
                       logHttp.info("Method:HttpClientUtil.executeHttpRequest---->請求返回狀態為200,url:" + url + ",返回結果:" + sb.toString());
                      return sb.toString();
                  }
                  catch (Exception e) {
                      logHttp.error("Method:HttpClientUtil.executeHttpRequest---->發生異常!請檢查網絡和參數", e);
                  }
                  finally {
                      postMethod.releaseConnection();
                  }
                  return null;
              }
          }
          posted on 2012-08-15 23:43 abin 閱讀(1077) 評論(0)  編輯  收藏 所屬分類: httpClient
          主站蜘蛛池模板: 巴青县| 双桥区| 启东市| 洛宁县| 巴林右旗| 滦平县| 合川市| 淳化县| 长岛县| 于都县| 大方县| 富源县| 前郭尔| 达拉特旗| 安泽县| 涿鹿县| 桃园市| 阿瓦提县| 翼城县| 渭南市| 东山县| 丰台区| 武威市| 麻栗坡县| 韶关市| 苏州市| 江门市| 河间市| 桂平市| 凉城县| 花垣县| 合作市| 溧阳市| 增城市| 北川| 宣武区| 乌拉特后旗| 安陆市| 台山市| 汕尾市| 从化市|