引用
模拟POST提交实现快盘签到
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
/**
* @author <a href="mailto:foohsinglong@gmail.com">kevin.long</a>
* @description
*/
public class TestKlive {
private static HttpClient hc = new DefaultHttpClient();
public static String postXml(String url, String xmlData) {
String body = null;
try {
HttpPost httppost = new HttpPost(url);
httppost.setHeader("Content-Type", "text/xml;charset=utf-8");
httppost.setHeader("v", "2");
// 设置参数
httppost.setEntity(new StringEntity(xmlData));
// 发送请求
HttpResponse httpresponse = hc.execute(httppost);
// 获取返回数据
HttpEntity entity = httpresponse.getEntity();
body = EntityUtils.toString(entity);
if (entity != null) {
entity.consumeContent();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return body;
}
/**
* @param args
* @throws DocumentException
*/
public static void main(String[] args) throws DocumentException {
String getTokenUrl = "http://api-filesys.wps.cn/xsvr/login/";
String signUrl = "http://point.wps.cn/kpoints/submit/sign/";
StringBuffer xmlData = new StringBuffer();
xmlData.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><xLive><user>");
xmlData.append("jinshany000@sina.com");
xmlData.append("</user><password>");
xmlData.append("123456");
xmlData.append("</password><deviceId>greenx-a34064b5b75e0c100f52c6c0fe80d887|
GEBINWIN</deviceId><clientName>greenx</clientName><clientVersion>1.0.0.90</clientVersion></xLive>");
System.out.println(xmlData);
String body = postXml(getTokenUrl, xmlData.toString());
System.out.println(body);
Document document = DocumentHelper.parseText(body);
Element rootElt = document.getRootElement();
String userId = rootElt.elementTextTrim("userId");
String token = rootElt.elementTextTrim("token");
System.out.println("获取信息\t"+userId+":"+token);
xmlData.delete(0, xmlData.length());
xmlData.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><xLive><token>");
xmlData.append(token);
xmlData.append("</token><userId>");
xmlData.append(userId);
xmlData.append("</userId></xLive>");
body = postXml(signUrl, xmlData.toString());
System.out.println(body);
}
}
分享到:
相关推荐
用HttpClient实现文件下载需要满足:有一台web服务器,要下载的源文件需存放在web服务器的特定目录下。通过发起http请求实现文件下载功能。
HttpClient实现POST GET和文件下载 HttpClient实现POST GET和文件下载
通过HttpClient实现远程下载,本例子通过java代码实现
使用HttpClient4.5实现https请求忽略SSL证书验证工具类
java中跨项目使用httpclient实现数据交换
使用HttpClient实现文件的上传所需lib
Android使用HttpClient实现上传下载功能并监控进度
基于SSM+maven+httpClient+jsoup实现小说网站项目 基于SSM+maven+httpClient+jsoup实现小说网站项目 基于SSM+maven+httpClient+jsoup实现小说网站项目 基于SSM+maven+httpClient+jsoup实现小说网站项目 基于SSM+...
NULL 博文链接:https://zywang.iteye.com/blog/916489
利用c# httpclient ,post json数据到web api
NULL 博文链接:https://skymr.iteye.com/blog/1911341
HTTP异步工具包(HttpClient实现) http://blog.csdn.net/lyl_studio/article/details/9319549
httpclient 实现https双向认证
hp实现httpclient类示例,需要的朋友可以参考下,buffer 获取返回的字符串,referer 设置 HTTP_REFERER 的网址,response 服务器响应的 header 信息,request 发送到服务器的 header 信息。
Android Asynchronous HTTPClient的实现和优化
Android使用HttpClient实现上传下载功能并监控进度.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
HttpClient中文文档,快速开发
主要介绍了java实现HttpClient异步请求资源的方法,实例分析了java基于http协议实现异步请求的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
Angular中的数据请求 内置模块HttpClient实现(get post jsonp 以及第三方模板axios请求数据(32分12秒)