少年阿賓

          那些青春的歲月

            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 閱讀(1073) 評論(0)  編輯  收藏 所屬分類: httpClient
          主站蜘蛛池模板: 丰县| 大冶市| 宝兴县| 五大连池市| 手游| 迭部县| 肇庆市| 大兴区| 云霄县| 凤翔县| 江都市| 宁德市| 灵山县| 陆河县| 雅江县| 莎车县| 海门市| 永新县| 泰州市| 西乌珠穆沁旗| 博白县| 深圳市| 北安市| 房产| 唐海县| 南华县| 常熟市| 喀喇| 泰和县| 包头市| 云阳县| 交城县| 张家川| 安福县| 纳雍县| 通州市| 西华县| 涟源市| 八宿县| 陇西县| 鹤岗市|