如何Httpclient 与浏览器共享 Session???
我用httpclient登录某个网站后,如何跳到该网站,而不需要再登录。
http请求代码
@SuppressWarnings("finally")
public static String sendGetRequest(String requestUrl) {
long responseLength = 0; //响应长度
String responseContent = null; //响应内容
HttpClient httpClient = new DefaultHttpClient(); //创建默认的httpClient实例
HttpGet httpGet = new HttpGet(requestUrl); //创建HttpGet
try {
HttpResponse response = httpClient.execute(httpGet); //执行GET请求
HttpEntity entity = response.getEntity(); //获取响应实体
// new DefaultHttpClient().getco
if (null != entity) {
responseLength = entity.getContentLength();
responseContent = EntityUtils.toString(entity, "UTF-8");
EntityUtils.consume(entity); //Consume response content
}
System.out.println("请求地址: " + httpGet.getURI());
System.out.println("响应状态: " + response.getStatusLine());
System.out.println("响应长度: " + responseLength);
System.out.println("响应内容: " + responseContent);
} catch (Client
ProtocolException e) {
//该异常通常是协议错误导致
//比如构造HttpGet对象时传入的协议不对(将"http"写成"htp")或者服务器端返回的内容不符合HTTP协议要求等
e.printStackTrace();
} catch (
ParseException e) {
e.printStackTrace();
} catch (
webservice调用Spring里jdbctemplate的步骤