少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(22)

          我參與的團隊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

           
          京-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 閱讀(1075) 評論(0)  編輯  收藏 所屬分類: httpClient
          主站蜘蛛池模板: 额敏县| 准格尔旗| 新昌县| 平昌县| 宜春市| 安塞县| 左权县| 泰和县| 化德县| 东乌珠穆沁旗| 普洱| 宁乡县| 巨野县| 泰安市| 营口市| 丰都县| 阿拉善盟| 永康市| 大渡口区| 嘉善县| 西林县| 唐河县| 灵丘县| 德清县| 平江县| 彭山县| 罗平县| 南溪县| 元谋县| 景泰县| 黔东| 阿巴嘎旗| 农安县| 图们市| 南和县| 新巴尔虎右旗| 青田县| 建始县| 晋中市| 湛江市| 金山区|