java如何实现post请求webservice服务端

目录
  • post请求webservice服务端
    • 1.例如我此时有一个wsdl文件
    • 2.点击row查看具体的发送参数
    • 3.代码实现
    • 3.1参数说明
  • 用post请求调用webservice

post请求webservice服务端

当生成webService的客户端不好实现时,通过java的post请求不失为一种好办法。

1.例如我此时有一个wsdl文件

http://xxx.xxx.xxx.xxx:8081/APIService.svc?wsdl

2.通过SoapUI 我们可以将swdl文件转换。从而模拟发送请求。以及参数

(不懂soapui请自行百度)

2.点击row查看具体的发送参数

具体参数对应规则(以下对应代码上应该发送的参数是什么)

3.代码实现

  public static void main(String[] args) {
        try{
            String url="http://xxx.xxx.xxx.xxx:8081/APIService.svc";
            String params="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\" xmlns:hn=\"http://schemas.datacontract.org/2004/07/hn.DataAccess.bll\">\n" +
                    "         </tem:input>\n" +
                    "   </soapenv:Body>\n" +
                    "</soapenv:Envelope>";
            String host="xxx.xxx.xxx.xxx:8081";
            String SOAPAction="http://aaa/aaa/aaa";

            //接受返回报文
            String result = new String();
            URL u = new URL(url);
            HttpURLConnection conn = (HttpURLConnection) u.openConnection();
            conn.setDoInput(true);
            //允许对外输出数据
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            conn.setDefaultUseCaches(false);
            conn.setRequestProperty("Host",host);
            conn.setRequestProperty("Content-Type","text/xml;charset=UTF-8");
            //soap
            conn.setRequestProperty("SOAPAction",SOAPAction);
            conn.setRequestProperty("Content-Length",String.valueOf(params.length()));
            conn.setRequestMethod("POST");
            //定义输出流
            OutputStream output = conn.getOutputStream();
            if(StringUtils.isNotBlank(params)){
                byte[] b = params.getBytes("UTF-8");
                //发送soap请求报文
                output.write(b,0,b.length);
                output.flush();
                output.close();
                //定义输入流,获取soap报文
                InputStream input = conn.getInputStream();
                //设置编码格式
                result = IOUtils.toString(input,"UTF-8");
                input.close();
            }
            System.out.println("请求返回报文:" + result);
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }

3.1参数说明

  • url:这个地址即wsdl文件地址去掉后缀  “?wsdl”。如此例就是:
  • wsdl
http://xxx.xxx.xxx.xxx:8081/APIService.svc?wsdl
  • url
http://xxx.xxx.xxx.xxx:8081/APIService.svc
  • params:这个即是请求的参数
  • host:这个是对方的主机地址和端口号。 如此例为:  xxx.xxx.xxx.xxx:8081
  • SOAPAction:具体service路径

用post请求调用webservice

先说下遇到的坑,最先用post请求的时候一直返回500的错误码

最终通过打印错误信息分析,请求头必须添加SOAPAction

//请求头必须设置SOAPAction
connection.setRequestProperty("SOAPAction","application/soap+xml; charset=utf-8"); 

xml转json需要用到hutool-all-4.0.12.jar,解析json比xml要简单得多。

如果不需要用xml转json,除需要jdk自带的包不再需要引入其他的包。

package com.baidu.util;
import cn.hutool.json.XML;
import net.sf.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * @author 蓝珂一剑
 * @version 1.0.0
 * @ClassName SoapUtil.java
 * @Description webservice调用工具类
 * @createTime 2020/9/29 10:37
 */
public class SoapUtil {

    /**
     * 发送http post调用webservice
     *
     * @param strUrl
     * @param requestSoapXml
     * @return
     * @throws IOException
     */
    public static String soapPost(String strUrl, String requestSoapXml) throws IOException {
        //第一步:创建服务地址,不是WSDL地址
        URL url = new URL(strUrl);
        //第二步:打开一个通向服务地址的连接
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        //第三步:设置参数
        //3.1发送方式设置:POST必须大写
        connection.setRequestMethod("POST");
        //3.2设置数据格式:content-type
        connection.setRequestProperty("content-type", "text/xml;charset=utf-8");
        //3.3设置输入输出,因为默认新创建的connection没有读写权限,
        connection.setDoInput(true);
        connection.setDoOutput(true);
        //请求头必须设置SOAPAction
        connection.setRequestProperty("SOAPAction","application/soap+xml; charset=utf-8");
        //第四步:组织SOAP数据,发送请求
        OutputStream os = connection.getOutputStream();
        //os.write(requestSoapXml.getBytes());这个方法遇到一个大坑记录下
        //当时在开发工具中通过这个方法调用接口一切都OK,但是放到客户服务器上发送post
        //请求就返回500错误,错误信息太少,走了很多弯路,百度无果后,
        //后面灵机一动,会不会是传输的数据编码不对,
        //导致接口服务端解析请求数据报错从而返回500错误码,
        //其实我是不知道服务端到底用的什么编码,
        //经过尝试 os.write(requestSoapXml.getBytes("utf-8"));
        //结果成功了,根据实际情况这个编码会改动
        os.write(requestSoapXml.getBytes());
        //第五步:接收服务端响应,打印
        int responseCode = connection.getResponseCode();
        //==============打印错误信息
//        try{
//            InputStream iss = connection.getErrorStream();    //通过getErrorStream了解错误的详情
//            InputStreamReader isrs = new InputStreamReader(iss,"utf-8");
//            BufferedReader ins = new BufferedReader(isrs);
//            String inputLine;
//            BufferedWriter bws = new BufferedWriter(new OutputStreamWriter(
//                    new FileOutputStream("result.xml")));// 将结果存放的位置
//            while ((inputLine = ins.readLine()) != null)
//            {
//                System.out.println(inputLine);
//                bws.write(inputLine);
//                bws.newLine();
//
//            }
//            bws.close();
//        }catch (Exception e){
//
//        }
        //==============
        StringBuilder sb = new StringBuilder();
        if (200 == responseCode) {//表示服务端响应成功
            InputStream is = connection.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);

            String temp = null;
            while (null != (temp = br.readLine())) {
                sb.append(temp);
            }
            is.close();
            isr.close();
            br.close();
        }else{
            throw new RuntimeException("调用webservice失败:服务器端返回HTTP code " + responseCode + "信息:" );
        }

        os.close();
        return sb.toString();
    }

    public static void main(String[] args)  {
        String url = "http://192.168.100.86:6888/ormrpc/services/WSImpExtFaCardFacade";
        String p = "<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://webservice.app.manage.fa.fi.eas.kingdee.com\">\n" +
                "   <soapenv:Header/>\n" +
                "   <soapenv:Body>\n" +
                "      <web:impFaCard soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
                "         <jsonStr xsi:type=\"xsd:string\">{\"header\":{\"bizcode\":\"42AC39EC\",\"bizdate\":\"2020-10-12\"},\"datas\":[{\"companynum\":\"D01\",\"facatnum\":\"04\",\"number\":\"JD04202010120000175\",\"oldnumber\":\"\",\"assetname\":\"服务器\",\"assetamount\":\"1\",\"measureunitnum\":\"件\",\"recorddate\":\"2020-10-12\",\"fiaccountdate\":\"2020-10-12\",\"originnum\":\"00101\",\"fausestatusnum\":\"101\",\"economypurposenum\":\"001\",\"storecitynum\":\"001\",\"specs\":\" \",\"parea\":\"\",\"manufacturer\":\"\",\"leavefactorydate\":\"\",\"paperno\":\"\",\"fromunit\":\"-1\",\"deptnum\":\"JD.001\",\"keepernum\":\"EP17019484\",\"remark\":\"\",\"currencynum\":\"BB01\",\"exchangerate\":\"1\",\"originalamount\":\"12000.0\",\"additiveamount\":\"0\",\"localamount\":\"12000.0\",\"inputtax\":\"0\",\"fairvalue\":\"0\",\"buyoriginalvalue\":\"0\",\"buyaddupdep\":\"0\",\"treatmentincome\":\"0\",\"deliverdate\":\"\",\"startdate\":\"2020-10-12\",\"expuseyears\":\"5\",\"expuseperiod\":\"60\",\"depperiod\":\"0\",\"addupdep\":\"0\",\"neatleftrate\":\"0\",\"expneatleftvalue\":\"3600.0\",\"neatvalue\":\"12000.0\",\"addupdepthisyear\":\"0\",\"decprepare\":\"0\",\"neatamount\":\"12000.0\",\"deprmethodnum\":\"0\",\"measureunitwlnum\":\"\",\"accountassetsnum\":\"04\",\"accountaccudeprnum\":\"04\",\"accountdecvaluenum\":\"04\",\"initevalvalue\":\"0\",\"evalperiodleft\":\"0\",\"accudeprall\":\"0\",\"hasdisabled\":\"0\",\"addonfare\":\"0\",\"monthrate\":\"0\",\"wrtyperiod\":\"\",\"wrtynumber\":\"\",\"groupnumber\":\"\",\"barcode\":\"JD04202010120000175\",\"usedepartmentnum\":\"JD.001\",\"usepersonnum\":\"\",\"usage\":\"\",\"asstacttypenum\":\"CBZX\",\"asstactitemnum\":\"Y0101\",\"accountnum\":\"6602.05\",\"apportionscale\":\"100\"},{\"companynum\":\"D01\",\"facatnum\":\"04\",\"number\":\"JD04202010120000176\",\"oldnumber\":\"\",\"assetname\":\"服务器\",\"assetamount\":\"1\",\"measureunitnum\":\"件\",\"recorddate\":\"2020-10-12\",\"fiaccountdate\":\"2020-10-12\",\"originnum\":\"00101\",\"fausestatusnum\":\"101\",\"economypurposenum\":\"001\",\"storecitynum\":\"001\",\"specs\":\" \",\"parea\":\"\",\"manufacturer\":\"\",\"leavefactorydate\":\"\",\"paperno\":\"\",\"fromunit\":\"-1\",\"deptnum\":\"JD.001\",\"keepernum\":\"EP17019484\",\"remark\":\"\",\"currencynum\":\"BB01\",\"exchangerate\":\"1\",\"originalamount\":\"12000.0\",\"additiveamount\":\"0\",\"localamount\":\"12000.0\",\"inputtax\":\"0\",\"fairvalue\":\"0\",\"buyoriginalvalue\":\"0\",\"buyaddupdep\":\"0\",\"treatmentincome\":\"0\",\"deliverdate\":\"\",\"startdate\":\"2020-10-12\",\"expuseyears\":\"5\",\"expuseperiod\":\"60\",\"depperiod\":\"0\",\"addupdep\":\"0\",\"neatleftrate\":\"0\",\"expneatleftvalue\":\"3600.0\",\"neatvalue\":\"12000.0\",\"addupdepthisyear\":\"0\",\"decprepare\":\"0\",\"neatamount\":\"12000.0\",\"deprmethodnum\":\"0\",\"measureunitwlnum\":\"\",\"accountassetsnum\":\"04\",\"accountaccudeprnum\":\"04\",\"accountdecvaluenum\":\"04\",\"initevalvalue\":\"0\",\"evalperiodleft\":\"0\",\"accudeprall\":\"0\",\"hasdisabled\":\"0\",\"addonfare\":\"0\",\"monthrate\":\"0\",\"wrtyperiod\":\"\",\"wrtynumber\":\"\",\"groupnumber\":\"\",\"barcode\":\"JD04202010120000176\",\"usedepartmentnum\":\"JD.001\",\"usepersonnum\":\"\",\"usage\":\"\",\"asstacttypenum\":\"CBZX\",\"asstactitemnum\":\"Y0101\",\"accountnum\":\"6602.05\",\"apportionscale\":\"100\"},{\"companynum\":\"D01\",\"facatnum\":\"04\",\"number\":\"JD04202010120000177\",\"oldnumber\":\"\",\"assetname\":\"服务器\",\"assetamount\":\"1\",\"measureunitnum\":\"件\",\"recorddate\":\"2020-10-12\",\"fiaccountdate\":\"2020-10-12\",\"originnum\":\"00101\",\"fausestatusnum\":\"101\",\"economypurposenum\":\"001\",\"storecitynum\":\"001\",\"specs\":\" \",\"parea\":\"\",\"manufacturer\":\"\",\"leavefactorydate\":\"\",\"paperno\":\"\",\"fromunit\":\"-1\",\"deptnum\":\"JD.001\",\"keepernum\":\"EP17019484\",\"remark\":\"\",\"currencynum\":\"BB01\",\"exchangerate\":\"1\",\"originalamount\":\"12000.0\",\"additiveamount\":\"0\",\"localamount\":\"12000.0\",\"inputtax\":\"0\",\"fairvalue\":\"0\",\"buyoriginalvalue\":\"0\",\"buyaddupdep\":\"0\",\"treatmentincome\":\"0\",\"deliverdate\":\"\",\"startdate\":\"2020-10-12\",\"expuseyears\":\"5\",\"expuseperiod\":\"60\",\"depperiod\":\"0\",\"addupdep\":\"0\",\"neatleftrate\":\"0\",\"expneatleftvalue\":\"3600.0\",\"neatvalue\":\"12000.0\",\"addupdepthisyear\":\"0\",\"decprepare\":\"0\",\"neatamount\":\"12000.0\",\"deprmethodnum\":\"0\",\"measureunitwlnum\":\"\",\"accountassetsnum\":\"04\",\"accountaccudeprnum\":\"04\",\"accountdecvaluenum\":\"04\",\"initevalvalue\":\"0\",\"evalperiodleft\":\"0\",\"accudeprall\":\"0\",\"hasdisabled\":\"0\",\"addonfare\":\"0\",\"monthrate\":\"0\",\"wrtyperiod\":\"\",\"wrtynumber\":\"\",\"groupnumber\":\"\",\"barcode\":\"JD04202010120000177\",\"usedepartmentnum\":\"JD.001\",\"usepersonnum\":\"\",\"usage\":\"\",\"asstacttypenum\":\"CBZX\",\"asstactitemnum\":\"Y0101\",\"accountnum\":\"6602.05\",\"apportionscale\":\"100\"},{\"companynum\":\"D01\",\"facatnum\":\"04\",\"number\":\"JD04202010120000178\",\"oldnumber\":\"\",\"assetname\":\"服务器\",\"assetamount\":\"1\",\"measureunitnum\":\"件\",\"recorddate\":\"2020-10-12\",\"fiaccountdate\":\"2020-10-12\",\"originnum\":\"00101\",\"fausestatusnum\":\"101\",\"economypurposenum\":\"001\",\"storecitynum\":\"001\",\"specs\":\" \",\"parea\":\"\",\"manufacturer\":\"\",\"leavefactorydate\":\"\",\"paperno\":\"\",\"fromunit\":\"-1\",\"deptnum\":\"JD.001\",\"keepernum\":\"EP17019484\",\"remark\":\"\",\"currencynum\":\"BB01\",\"exchangerate\":\"1\",\"originalamount\":\"12000.0\",\"additiveamount\":\"0\",\"localamount\":\"12000.0\",\"inputtax\":\"0\",\"fairvalue\":\"0\",\"buyoriginalvalue\":\"0\",\"buyaddupdep\":\"0\",\"treatmentincome\":\"0\",\"deliverdate\":\"\",\"startdate\":\"2020-10-12\",\"expuseyears\":\"5\",\"expuseperiod\":\"60\",\"depperiod\":\"0\",\"addupdep\":\"0\",\"neatleftrate\":\"0\",\"expneatleftvalue\":\"3600.0\",\"neatvalue\":\"12000.0\",\"addupdepthisyear\":\"0\",\"decprepare\":\"0\",\"neatamount\":\"12000.0\",\"deprmethodnum\":\"0\",\"measureunitwlnum\":\"\",\"accountassetsnum\":\"04\",\"accountaccudeprnum\":\"04\",\"accountdecvaluenum\":\"04\",\"initevalvalue\":\"0\",\"evalperiodleft\":\"0\",\"accudeprall\":\"0\",\"hasdisabled\":\"0\",\"addonfare\":\"0\",\"monthrate\":\"0\",\"wrtyperiod\":\"\",\"wrtynumber\":\"\",\"groupnumber\":\"\",\"barcode\":\"JD04202010120000178\",\"usedepartmentnum\":\"JD.001\",\"usepersonnum\":\"\",\"usage\":\"\",\"asstacttypenum\":\"CBZX\",\"asstactitemnum\":\"Y0101\",\"accountnum\":\"6602.05\",\"apportionscale\":\"100\"},{\"companynum\":\"D01\",\"facatnum\":\"04\",\"number\":\"JD04202010120000179\",\"oldnumber\":\"\",\"assetname\":\"服务器\",\"assetamount\":\"1\",\"measureunitnum\":\"件\",\"recorddate\":\"2020-10-12\",\"fiaccountdate\":\"2020-10-12\",\"originnum\":\"00101\",\"fausestatusnum\":\"101\",\"economypurposenum\":\"001\",\"storecitynum\":\"001\",\"specs\":\" \",\"parea\":\"\",\"manufacturer\":\"\",\"leavefactorydate\":\"\",\"paperno\":\"\",\"fromunit\":\"-1\",\"deptnum\":\"JD.001\",\"keepernum\":\"EP17019484\",\"remark\":\"\",\"currencynum\":\"BB01\",\"exchangerate\":\"1\",\"originalamount\":\"12000.0\",\"additiveamount\":\"0\",\"localamount\":\"12000.0\",\"inputtax\":\"0\",\"fairvalue\":\"0\",\"buyoriginalvalue\":\"0\",\"buyaddupdep\":\"0\",\"treatmentincome\":\"0\",\"deliverdate\":\"\",\"startdate\":\"2020-10-12\",\"expuseyears\":\"5\",\"expuseperiod\":\"60\",\"depperiod\":\"0\",\"addupdep\":\"0\",\"neatleftrate\":\"0\",\"expneatleftvalue\":\"3600.0\",\"neatvalue\":\"12000.0\",\"addupdepthisyear\":\"0\",\"decprepare\":\"0\",\"neatamount\":\"12000.0\",\"deprmethodnum\":\"0\",\"measureunitwlnum\":\"\",\"accountassetsnum\":\"04\",\"accountaccudeprnum\":\"04\",\"accountdecvaluenum\":\"04\",\"initevalvalue\":\"0\",\"evalperiodleft\":\"0\",\"accudeprall\":\"0\",\"hasdisabled\":\"0\",\"addonfare\":\"0\",\"monthrate\":\"0\",\"wrtyperiod\":\"\",\"wrtynumber\":\"\",\"groupnumber\":\"\",\"barcode\":\"JD04202010120000179\",\"usedepartmentnum\":\"JD.001\",\"usepersonnum\":\"\",\"usage\":\"\",\"asstacttypenum\":\"CBZX\",\"asstactitemnum\":\"Y0101\",\"accountnum\":\"6602.05\",\"apportionscale\":\"100\"}]}</jsonStr>\n" +
                "      </web:impFaCard>\n" +
                "   </soapenv:Body>\n" +
                "</soapenv:Envelope>";
       try{
           String response = SoapUtil.soapPost(url,p);
           cn.hutool.json.JSONObject data = XML.toJSONObject(response);
           //从data中解析rescode和resmsg,其中"rescode"为0时代表成功,其他均为失败。
           String resMsg = data.getJSONObject("soapenv:Envelope").getJSONObject("soapenv:Body").getJSONObject("ns1:impFaCardResponse").getJSONObject("impFaCardReturn").getStr("content");
           JSONObject jsonObject = JSONObject.fromObject(resMsg);
           String bizcode = jsonObject.getString("bizcode");
           String bizdate = jsonObject.getString("bizdate");
           String rescode = jsonObject.getString("rescode");
           String resmsg = jsonObject.getString("resmsg");
           System.out.println(resmsg);
       }catch (Exception e){
           e.printStackTrace();
       }
    }
}

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • java实现简单的webservice方式

    本文实例为大家分享了java实现webservice方式的具体代码,供大家参考,具体内容如下 经过测试 jdk1.6.10以下会出现bug 建议使用10以上版本 1.定义接口 package org.enson.chan; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; @WebService @SOAPBinding(style=SOAPBinding.Style.RPC) public interface IMy

  • java WSDL接口webService实现方式

    一.使用JDK生成WSDL的对象类 1.cmd进入JDK的bin文件中 执行命令 wsimport -keep -p com.demo.client http://localhost:8080/Demo/services/MyService?wsdl 比较常用的[options]有: 1). -d <directory> 在指定的目录生成class文件 2). -clientjar <jarfile> 在当前目录生成jar文件,结合-d <directory>可以在指定

  • java调用WebService服务的四种方法总结

    目录 一.前言 二.简介   三.具体解析 第一种方式,首先得下载axis2的jar包,Axis2提供了一个wsdl2java.bat命令可以根据WSDL文件自动产生调用WebService的代码. 第二种RPC 方式,强烈推荐. 第三种:利用HttpURLConnection拼接和解析报文进行调用. 第四种,利用httpclient 总结 一.前言 本来不想写这个的,因为网上类似的是在是太多了.但是想想自己前面段时间用过,而且以后可能再也没机会用了.所以还是记录一下吧.我这儿是以C语言生成的W

  • java如何实现post请求webservice服务端

    目录 post请求webservice服务端 1.例如我此时有一个wsdl文件 2.点击row查看具体的发送参数 3.代码实现 3.1参数说明 用post请求调用webservice post请求webservice服务端 当生成webService的客户端不好实现时,通过java的post请求不失为一种好办法. 1.例如我此时有一个wsdl文件 http://xxx.xxx.xxx.xxx:8081/APIService.svc?wsdl 2.通过SoapUI 我们可以将swdl文件转换.从而

  • Spring Boot 实现Restful webservice服务端示例代码

    1.Spring Boot configurations application.yml spring: profiles: active: dev mvc: favicon: enabled: false datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/wit_neptune?createDatabaseIfNotExist=true&useUnicode=true&

  • Java网络编程之简单的服务端客户端应用实例

    本文实例讲述了Java网络编程之简单的服务端客户端应用.分享给大家供大家参考.具体如下: 在Java中,我们使用java.net.Socket及其相关类来完成有关网络的相关功能.Socket类非常简单易用,因为Java技术隐藏了建立网络连接和通过连接发送数据的复杂过程.下面所说的内容只适用于TCP协议. 一.连接到服务器 我们可以使用Socket类的构造函数来打开一个套接字,如 Socket sk = new Socket("210.0.235.14",13); 其中,210.0.23

  • Java通过socket客户端保持连接服务端实现代码

    这篇文章主要介绍了Java通过socket客户端保持连接服务端实现代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 业务场景:现在有一个socket服务端给我们发送数据,我们需要建立一个socket Client来连接这个socket Server,然后接受server发送过来的数据.但是这个server可能会中断,所以在Client要有一个while死循环去时刻保持与Server的连接. package com.thinkgem.wlw.m

  • java Nio使用NioSocket客户端与服务端交互实现方式

    NioSocket 客户端与服务端交互实现 java Nio是jdk1.4新增的io方式-–nio(new IO),这种方式在目前来说算不算new,更合适的解释应该是non-block IO. non-block是相对于传统的io方式来讲的.传统的Io方式是阻塞的,我们拿网络io来举例,传统的io模型如下: 服务端主线程负责不断地server.accept(),如果没有客户端请求主线程就会阻塞,当客户端请求时,主线程会通过线程池创建一个新的线程执行. 简单解释就是一个线程负责一个客户端的sock

  • java实现socket客户端连接服务端

    本例只做简单功能演示,代码并不严谨,只是说明客户端如何实现连接服务端简单代码. 代码在集成Eclipse工具下测试编译运行环境如下图所示: 客户端echoClient.java代码: package com.zhengzz.echo; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java

  • SpringBoot整合WebService服务的实现代码

    目录 为什么使用WebService? 适用场景: 不适用场景: Axis2与CXF的区别 SpringBoot使用CXF集成WebService WebService是一个SOA(面向服务的编程)的架构,它是不依赖于语言,不依赖于平台,可以实现不同的语言间的相互调用,通过Internet进行基于Http协议的网络应用间的交互. 其实WebService并不是什么神秘的东西,它就是一个可以远程调用的类,或者说是组件,把你本地的功能开放出去共别人调用. 为什么使用WebService? 简单解释一

  • 详解Angular5 服务端渲染实战

    本文基于上一篇 Angular5 的文章继续进行开发,上文中讲了搭建 Angular5 有道翻译的过程,以及遇到问题的解决方案. 随后改了 UI,从 bootstrap4 改到 angular material,这里不详细讲,服务端渲染也与修改 UI 无关. 看过之前文章的人会发现,文章内容都偏向于服务端渲染,vue 的 nuxt,react 的 next. 在本次改版前也尝试去找类似 nuxt.js 与 next.js 的顶级封装库,可以大大节省时间,但是未果. 最后决定使用从 Angular

  • 详解服务端预渲染之Nuxt(介绍篇)

    现在前端开发一般都是前后端分离,mvvm和mvc的开发框架,如Angular.React和Vue等,虽然写框架能够使我们快速的完成开发,但是由于前后台分离,给项目SEO带来很大的不便,搜索引擎在检索的时候是在网页中爬取数据,由于单页面应用读取到的页面是几乎空白的,无法爬取到任何数据信息. <!DOCTYPE html> <html> <head> <meta charset=utf-8> <meta name=viewport content=&quo

  • Angular开发实践之服务端渲染

    Angular Universal Angular在服务端渲染方面提供一套前后端同构解决方案,它就是Angular Universal(统一平台),一项在服务端运行 Angular 应用的技术. 标准的 Angular 应用会执行在浏览器中,它会在 DOM 中渲染页面,以响应用户的操作. 而 Angular Universal 会在服务端通过一个被称为服务端渲染(server-side rendering - SSR)的过程生成静态的应用页面. 它可以生成这些页面,并在浏览器请求时直接用它们给出

随机推荐