package com.hand.hl; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.RequestEntity; import org.apache.commons.httpclient.methods.StringRequestEntity; /** * description * * @author lcl 2023/02/15 15:07 */ public class HttpPostUtilNew { public HttpPostUtilNew() { } public static String httpPostDocImport(String postUrl, String data, String token, String tokentype) { try { PostMethod postMethod = null; HttpClient httpClient = new HttpClient(); postMethod = new PostMethod(postUrl); RequestEntity entity = null; postMethod.setRequestHeader("Content-Type", "application/json"); postMethod.setRequestHeader("Authorization", tokentype + " " + token); entity = new StringRequestEntity(data, "application/json", "UTF-8"); postMethod.setRequestEntity(entity); System.out.println(data); httpClient.executeMethod(postMethod); String result = postMethod.getResponseBodyAsString(); return result; } catch (Exception var9) { return "{\n \"error\": \"interError\",\n \"message\": \"请求接口失败\",\n \"path\": \"/oauth/token\"\n}"; } } public static void main(String[] args) throws Exception { String resPonse = httpPostDocImport("http://apistage.huilianyi.com/gateway/e-archives/api/open/v1/import/document", "[{\"companyCode\":\"0001\",\"particularYear\":\"2022\",\"documentTypeCode\":\"DT002002\",\"originalNumber\":\"1234567890\",\"primaryField\":\"SAP_TEST0000001\",\"isPaper\":\"true\",\"documentSource\":\"SAP\",\"attachmentList\":[{\"fileURL\":\"https://gss0.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/314e251f95cad1c8ea88af74793e6709c93d51b5.jpg\",\"fileName\":\"314e251f95cad1c8ea88af74793e6709c93d51b5.jpg\",\"attachmentOID\":\"\"},{\"fileURL\":\"https://gss0.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/314e251f95cad1c8ea88af74793e6709c93d51b5.jpg\",\"fileName\":\"314e251f95cad1c8ea88af74793e6709c93d51b5.jpg\",\"attachmentOID\":\"\",\"attachTypeCode\":\"0\"}],\"ruleOID\":\"684fb42f-1df4-4710-8ac7-ea0146786a05\",\"securityLevelCode\":\"CONFIDENTIAL\",\"fieldValueList\":[{\"fieldCode\":\"AMOUNT\",\"value\":\"13\"},{\"fieldCode\":\"COMPANY\",\"value\":\"阳光照明\"},{\"fieldCode\":\"DOC_NAME\",\"value\":\"日常报销单\"},{\"fieldCode\":\"CURRENCY\",\"value\":\"CNY\"},{\"fieldCode\":\"CREATED_DATE\",\"value\":\"2021-01-01 12:00:00\"},{\"fieldCode\":\"CREATION_NAME\",\"value\":\"张三\"},{\"fieldCode\":\"REMARK\",\"value\":\"去年的报销\"}]}]", "4557fa35-d2da-479a-be68-323b6be619d9", "Bearer"); System.out.println(resPonse); } }