少年阿賓

          那些青春的歲月

            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
          主站蜘蛛池模板: 阳信县| 中阳县| 平塘县| 视频| 汉寿县| 双鸭山市| 宜宾市| 陈巴尔虎旗| 潞西市| 高安市| 南漳县| 游戏| 天镇县| 安义县| 志丹县| 阜城县| 高密市| 兴城市| 胶州市| 沭阳县| 手游| 宁明县| 桑日县| 安陆市| 吉林省| 民乐县| 正宁县| 鹰潭市| 基隆市| 花垣县| 宜兴市| 民乐县| 大渡口区| 焦作市| 宣武区| 吉安市| 镇康县| 阳城县| 五大连池市| 五华县| 夹江县|