欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

通过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();
		}
	}
}

 
通过HttpClient调用XDOC云服务
            
    
    博客分类: XDOC  
 

  • 通过HttpClient调用XDOC云服务
            
    
    博客分类: XDOC  
  • 大小: 64.1 KB