httpclient

六眼飞鱼酱① 提交于 2021-02-17 05:32:14

每次用,每次查,每次查,每次忘,这下忘不了了吧!

另,要这两个包,

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);
		}
	}



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!