/**
     * 调用人力系统事由劳务接收的接口
     * @param addr
     * @param targetspace
     * @param method
     * @param param
     * @param xml
     * @return
     * @throws Exception
     */
    public String callService(String xml) throws Exception{    
        //调用api接口方式 post
        //接口地址 客户给
        String url ="http://hcmcloud.ciecc.com.cn/api_outer/dynamic.script.for.common.api";
        String result = "";
        HttpClient httpClient =new HttpClient();
        
        httpClient.getParams().setContentCharset("UTF-8");
        PostMethod postMethod = new PostMethod(url);
        //token   客户给
        postMethod.setRequestHeader("OuterToken", "26e95930cc3855ee1efee40a8acdd5b65b0256bf");
        //方法名NC_LaborBackXml与返回值xml  客户给
        String body = " { \"param\": { \"plugin\": \"NC_LaborBackXml\", \"param\":  \""+xml+"\"} }";
        RequestEntity requestEntity = null;
        try {
            requestEntity = new StringRequestEntity(body,"application/json","UTF-8");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }  
        postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
        postMethod.setRequestEntity(requestEntity); 
        try {
            httpClient.executeMethod(postMethod);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            InputStream in = postMethod.getResponseBodyAsStream();
            int len = 0;
            byte[] buf = new byte[1024];
            while((len=in.read(buf))!=-1){
                out.write(buf, 0, len);
            }
            result = out.toString("UTF-8");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            postMethod.releaseConnection();
        }
        return result;
    }
    

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐