每次用,每次查,每次查,每次忘,這下忘不了了吧! java
另,要這兩個包, json
public void getResponseDetail(String url) { HttpServletResponse response = (HttpServletResponse) super.getContextParam(ServletActionContext.HTTP_RESPONSE); HttpClient httpClient = new HttpClient(); GetMethod getMethod = new GetMethod(url); try { //關閉鏈接 getMethod.setRequestHeader("Connection","close"); getMethod.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8"); int statusCode = httpClient.executeMethod(getMethod); if (statusCode != HttpStatus.SC_OK) { System.out.println("Method failed:" + getMethod.getStatusLine()); } else { String json = getMethod.getResponseBodyAsString(); renderText(response, FormatJson.showJson(json)); } getMethod.releaseConnection(); } catch (Exception e) { log.error("ProControlAction Exception,url = " + url, e); } }