通过HttpClient调用XDOC云服务
程序员文章站
2024-01-29 16:47:04
...
import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.PostMethod; /** * 通过HttpClient调用XDOC云服务 * @author xdoc */ public class XDocHttpClient { /** * @param args */ public static void main(String[] args) { try { HttpClient client = new HttpClient(); PostMethod method = new PostMethod("http://www.xdocin.com/xdoc"); method.getParams().setContentCharset("UTF-8"); method.addParameter(new NameValuePair("_xdoc", "./10001.xdoc")); method.addParameter(new NameValuePair("_format", "pdf")); method.addParameter(new NameValuePair("份号", "1")); method.addParameter(new NameValuePair("密级", "秘密")); method.addParameter(new NameValuePair("保密期限", "一年")); method.addParameter(new NameValuePair("紧急程度", "特急")); method.addParameter(new NameValuePair("发文机关", "XDOC智能云文档平台")); method.addParameter(new NameValuePair("机关代字", "农")); method.addParameter(new NameValuePair("年份", "2015")); method.addParameter(new NameValuePair("发文顺序号", "1")); method.addParameter(new NameValuePair("标题", "关于XDOC智能云文档支持标准公文的通知")); method.addParameter(new NameValuePair("正文", " XDOC公文模板严格遵循GB/9704-2012《党政机关公文格式》。部署在XDOC云服务器是上,免费提供给大家使用。\n http://www.xdocin.com")); method.addParameter(new NameValuePair("发文机关署名", "XDOC办公室")); method.addParameter(new NameValuePair("成文日期", "2015-01-01")); method.addParameter(new NameValuePair("印章", "http://www.xdocin.com/xdoc.png")); method.addParameter(new NameValuePair("抄送机关", "XDOC老用户、新用户、爱好者。")); method.addParameter(new NameValuePair("印发机关", "XDOC办公室")); method.addParameter(new NameValuePair("印发日期", "2015-01-01")); method.addParameter(new NameValuePair("附注", "")); client.executeMethod(method); InputStream in = method.getResponseBodyAsStream(); FileOutputStream out = new FileOutputStream("c:/xdoc.pdf"); int len; byte[] buf = new byte[4096]; while (true) { len = in.read(buf); if (len > 0) { out.write(buf, 0, len); } else { break; } } out.flush(); in.close(); out.close(); method.releaseConnection(); } catch (IOException e) { e.printStackTrace(); } } }
下一篇: Node.js实现文件上传
推荐阅读
-
通过HttpClient调用XDOC云服务
-
通过HttpClient 调用ASP.NET Web API示例
-
通过postman调用webservice接口服务
-
通过C#调用cmd来修改服务启动类型
-
通过HttpClient 调用ASP.NET Web API示例
-
通过C#调用cmd来修改服务启动类型
-
“亲宝宝”完成数亿元C轮融资 通过云空间服务切入智能育儿
-
Android 客户端通过内置API(HttpClient) 访问 服务器(用Spring MVC 架构) 返回的json数据全过程
-
云服务centos搭建jupyter notebook并通过外网访问
-
Django从零搭建个人博客 | 通过IIS部署腾讯云Winsows服务器