admin管理员组文章数量:1559111
packagecom.platform.utilmon;importjava.io.ioexception;importjava.io.unsupportedencodingexception;importjava.util.arraylist;importjava.util.list;importjava.util.map;importjava.util.set;importorg.apache.http.httpentity;importorg.apache.http.httpresponse;importorg.apache.http.namevaluepair;importorg.apache.http.parseexception;importorg.apache.http.client.clientprotocolexception;importorg.apache.http.client.entity.urlencodedformentity;importorg.apache.http.client.methods.httpget;importorg.apache.http.client.methods.httppost;importorg.apache.http.client.methods.httpurirequest;importorg.apache.http.impl.client.defaulthttpclient;importorg.apache.http.message.basicnamevaluepair;importorg.apache.http.protocol.http;importorg.apache.http.util.entityutils;importorg.apache.log4j.logger;/***
* ============================================
* 功能描述:发送post/get请求
============================================*/
public classhttpxmlclient {private static logger log = logger.getlogger(httpxmlclient.class);public static string post(string url, mapparams) {
defaulthttpclient httpclient= newdefaulthttpclient();
string body= null;
log.info("create httppost:" url);
httppost post=postform(url, params);
body=invoke(httpclient, post);
httpclient.getconnectionmanager().shutdown();returnbody;
}public staticstring get(string url) {
defaulthttpclient httpclient= newdefaulthttpclient();
string body= null;
log.info("create httppost:" url);
httpget get= newhttpget(url);
body=invoke(httpclient, get);
httpclient.getconnectionmanager().shutdown();returnbody;
}private staticstring invoke(defaulthttpclient httpclient,
httpurirequest httpost) {
httpresponse response=sendrequest(httpclient, httpost);
string body=paseresponse(response);returnbody;
}private staticstring paseresponse(httpresponse response) {
log.info("get response from http server..");
httpentity entity=response.getentity();
log.info("response status: " response.getstatusline());
string charset=entityutils.getcontentcharset(entity);
log.info(charset);
string body= null;try{
body=entityutils.tostring(entity);
log.info(body);
}catch(parseexception e) {
e.printstacktrace();
}catch(ioexception e) {
e.printstacktrace();
}returnbody;
}private statichttpresponse sendrequest(defaulthttpclient httpclient,
httpurirequest httpost) {
log.info("execute post...");
httpresponse response= null;try{
response=httpclient.execute(httpost);
}catch(clientprotocolexception e) {
e.printstacktrace();
}catch(ioexception e) {
e.printstacktrace();
}returnresponse;
}private static httppost postform(string url, mapparams){
httppost httpost= newhttppost(url);
list nvps = new arraylist ();
set keyset =params.keyset();for(string key : keyset) {
nvps.add(newbasicnamevaluepair(key, params.get(key)));
}try{
log.info("set utf-8 form entity to httppost");
httpost.setentity(newurlencodedformentity(nvps, http.utf_8));
}catch(unsupportedencodingexception e) {
e.printstacktrace();
}returnhttpost;
}
}
j9九游会老哥俱乐部交流区的版权声明:本文标题:腾讯企业邮箱api java_腾讯企业邮箱api实现单点登录和获取企业未读邮件 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1727421244a1113607.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。