HttpClient client = new HttpClient();
client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY);
// 1
GetMethod authget = new GetMethod("httpwww.sample.comsampleAppsample.rss");
try {
client.executeMethod(authget);
}
catch (HttpException httpe) {
httpe.printStackTrace();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
// 2
NameValuePair[] data = new NameValuePair[2];
data[0] = new NameValuePair("j_username", username);
data[1] = new NameValuePair("j_password", password);
PostMethod authpost = new PostMethod("http://www.sample.com/sampleApp/j_security_check");
authpost.setRequestBody(data);
// 3
Header hCookie = authget.getRequestHeader("Cookie");
Header hHost = authget.getRequestHeader("Host");
Header hUserAgent = authget.getRequestHeader("User-Agent");
if (hCookie == null || hHost == null || hUserAgent == null) {
return null;
}
authpost.setRequestHeader(hCookie);
authpost.setRequestHeader(hHost);
authpost.setRequestHeader(hUserAgent);
authget.releaseConnection();
try {
client.executeMethod(authpost);
// 4
Header header = authpost.getResponseHeader("location");
if (header != null) {
String newuri = header.getValue();
GetMethod redirect = new GetMethod(newuri);
client.executeMethod(redirect);
// process the content from the response
redirect.releaseConnection();
}
} catch (HttpException httpe) {
httpe.printStackTrace();
return null;
} catch (IOException ioe) {
ioe.printStackTrace();
return null;
}
authpost.releaseConnection();
相关推荐
这是一个关于httpclient4.5访问https网站的例子,可以绕过ssl认证直接访问
httpclient 实现https双向认证
使用HttpClient4.5实现https请求忽略SSL证书验证工具类
httpClient 教程 使用事例 单向认证
以上自己测试是可行的,直接拿过去导入即可,直接用main
3.调用HttpClient对象的execute(HttpUriRequest request)发送请求,该方法返回一个HttpResponse。 client.executeMethod(method); 5. 调用HttpResponse的getAllHeaders()、getHeaders(String name)等方法可获取...
http远程接口调用-httpClient+跳过SSL证书校验. 里面分别有3个httpClient的工具类代码。 还有一个专门为了跳过SSL证书校验的工具类。
NULL 博文链接:https://liudeh-009.iteye.com/blog/1181571
所访问的这些页面有的仅仅是一些普通的页面,有的需要用户登录后方可使用,或者需要认证以及是一些通过加密方式传输,例如HTTPS。目前我们使用的浏览器处理这些情况都不会构成问题。不过你可能在某些时候需要通过...
NULL 博文链接:https://bewithme.iteye.com/blog/1938178
复制进eclipse即可用。main方法测试
出于安全性的需要和用户授权管理的考虑,常见的 J2EE 站点对特定资源都会加入认证/授权机制。例如一个公网上的论坛,一个只对特定用户开放的 RSS 或 Atom Feed,这些资源都必须在确信访问者为被授权用户时才能向访问...
得到的HttpClient在执行请求时将自动携带身份认证信息,并检查应答的微信支付签名。 项目状态 当前版本0.2.2为测试版本。请商户的专业技术人员在使用时注意系统和软件的正确性和兼容性,以及带来的风险。 环境要求 ...
HttpClient post请求(用于key-value格式的参数), post请求(用于请求json格式的参数),加入了请求头以及token认证,成功之后读取服务器返回过来的json字符串数据
https 的支持单向认证 支持多线程 支持get、post
包含连接管理、Http状态管理、HTTP认证、快速APi、HTTP缓存等
本资源为HttpClient教程,分为7个大的章节,从概念到连接管理,以及Http状态管理,http认证,快速API,HTTP缓存以及一些高级应用全方位仔仔细细认认真真的讲解。
基于java的HTTPS模拟上传,只有一个类和一个测试类。主要解决java模拟https上传文件使用
httpclient模拟浏览器中一个表单提交或者说异步提交的方法,返回通常为json或xml的格式,可以采用POST和GET传送并设置字符集以及超时控制。 URL暴露方式双方约定认证协议方法即可,另一种是获取cookie方式,但是...
httpclient-4.5.3中文版.CHM org.apache.http.auth 客户端HTTP认证API。 org.apache.http.auth.params 已过时。 org.apache.http.client 客户端HTTP通信API。 org.apache.http.client.config 客户端配置API。 ...