restful接口客户端和服务端开发,HttpURLConnection,HttpClient,post ,get方式调用

2023-10-27

Restful服务端及客户端调用实例

1.    新建web工程作为服务端à创建服务端代码

前情提示:

GET(SELECT):从服务器取出资源(一项或多项)。

POST(CREATE):在服务器新建一个资源。

PUT(UPDATE):在服务器更新资源(客户端提供改变后的完整资源)。

PATCH(UPDATE):在服务器更新资源(客户端提供改变的属性)。

DELETE(DELETE):从服务器删除资源。

2.服务端代码(每个方法前有注释,包括单参数,多参数,post,get方式的例子)

package com.eviac.blog.restws; 

import javax.ws.rs.Consumes;

import javax.ws.rs.DefaultValue;

import javax.ws.rs.FormParam;

import javax.ws.rs.GET; 

import javax.ws.rs.POST;

import javax.ws.rs.Path; 

import javax.ws.rs.PathParam; 

import javax.ws.rs.Produces;  

import javax.ws.rs.core.MediaType; 

 

import net.sf.json.JSONObject;

 

import com.alibaba.fastjson.JSONArray;

/**

 * 

 * @author pavithra

 * 

 */ 

 

// 这里@Path定义了类的层次路径。 

// 指定了资源类提供服务的URI路径。 

@Path("UserInfoService") 

public class UserInfo { 

    // @GET表示方法会处理HTTP GET请求 

    @GET 

    // 这里@Path定义了类的层次路径。指定了资源类提供服务的URI路径。 

   @Path("/name/{i}") 

    // @Produces定义了资源类方法会生成的媒体类型。 

   @Produces(MediaType.TEXT_XML) 

    // @PathParam向@Path定义的表达式注入URI参数值。 

    public String userName(@PathParam("i") 

    String i) { 

        String name = i; 

        return"<User>" + "<Name>" + name +"</Name>" + "</User>"; 

    } 

   

   

    @GET

    // 这里@Path定义了类的层次路径。指定了资源类提供服务的URI路径。 

   @Path("/userinfo/{id}") 

    // @Produces定义了资源类方法会生成的媒体类型

   //@Consumes(MediaType.APPLICATION_JSON) //传json

   @Produces(MediaType.APPLICATION_JSON) 

    // @PathParam向@Path定义的表达式注入URI参数值。 

    public StringuserJson(@PathParam("id") 

    String id) {

       //JSONObjectjobj=JSONObject.fromObject(id);

       //id=jobj.getString("id");

        return"{\"name\":\"hanzl\",\"age\":1,\"id\":"+"\""+id+"\"}"; 

    } 

   

  

    //多参数测试 

    @POST

    // 这里@Path定义了类的层次路径。指定了资源类提供服务的URI路径。 

   @Path("/user2info") 

    // @Produces定义了资源类方法会生成的媒体类型

   //@Consumes(MediaType.APPLICATION_JSON) //传json

    //多参数配置

    @Consumes({MediaType.MULTIPART_FORM_DATA,MediaType.APPLICATION_FORM_URLENCODED})

   @Produces(MediaType.APPLICATION_JSON) //返回json

    // @PathParam向@Path定义的表达式注入URI参数值。 

    public Stringuser2Json(@FormParam("id")

    Stringid,@FormParam("name") String name) {

       System.out.println(id);

       System.out.println(name);

        return"{\"name\":"+"\""+name+"\""+",\"age\":1,\"id\":"+"\""+id+"\"}";

    } 

 

   

  //多参数测试   参数为json

    @POST

    // 这里@Path定义了类的层次路径。指定了资源类提供服务的URI路径。 

   @Path("/user3info") 

    // @Produces定义了资源类方法会生成的媒体类型

   //@Consumes(MediaType.APPLICATION_JSON) //传json

    //多参数配置

    @Consumes({MediaType.MULTIPART_FORM_DATA,MediaType.APPLICATION_FORM_URLENCODED})

   @Produces(MediaType.APPLICATION_JSON) //返回json

    // @PathParam向@Path定义的表达式注入URI参数值。 

    public Stringuser3Json(@FormParam("id")

    String id) {

       System.out.println(id);

        return"{\"name\":\"hanzl\",\"age\":1,\"id\":"+"\""+id+"\"}";

    } 

 

    @GET 

    @Path("/age/{j}") 

   @Produces(MediaType.TEXT_XML) 

    public StringuserAge(@PathParam("j") 

    int j) { 

        int age = j; 

        return"<User>" + "<Age>" + age +"</Age>" + "</User>"; 

    } 

3.配置服务端web.xml(restful接口发布地址)在web.xml中加入如下配置

<servlet> 

        <servlet-name>Jersey RESTService</servlet-name> 

        <servlet-class> 

           com.sun.jersey.spi.container.servlet.ServletContainer 

        </servlet-class> 

        <init-param> 

            <param-name> 

               com.sun.jersey.config.property.packages 

            </param-name> 

           <param-value>com.eviac.blog.restws</param-value> 

        </init-param> 

       <load-on-startup>1</load-on-startup> 

    </servlet> 

    <servlet-mapping> 

        <servlet-name>Jersey RESTService</servlet-name> 

       <url-pattern>/rest/*</url-pattern> 

</servlet-mapping>

4.编写客户端代码

4.1新建java工程

来进行服务端的第一次调用:

packagecom.eviac.blog.restclient; 

 

import javax.ws.rs.core.MediaType; 

 

importcom.sun.jersey.api.client.Client; 

importcom.sun.jersey.api.client.ClientResponse; 

importcom.sun.jersey.api.client.WebResource; 

importcom.sun.jersey.api.client.config.ClientConfig; 

importcom.sun.jersey.api.client.config.DefaultClientConfig; 

 

/**

 * 

 * @author pavithra

 * 

 */ 

publicclass UserInfoClient { 

 

    public static final String BASE_URI ="http://localhost:8080/RestflService"; 

    public static final String PATH_NAME ="/UserInfoService/name/"; 

    public static final String PATH_AGE ="/UserInfoService/age/"; 

 

    public static void main(String[] args){ 

 

        String name ="Pavithra"; 

        int age = 25; 

 

        ClientConfig config = newDefaultClientConfig(); 

 

        Client client =Client.create(config); 

        WebResource resource =client.resource(BASE_URI); 

 

        WebResource nameResource =resource.path("rest").path(PATH_NAME + name); 

        System.out.println("ClientResponse \n" 

                +getClientResponse(nameResource)); 

        System.out.println("Response\n" + getResponse(nameResource) + "\n\n"); 

 

        WebResource ageResource =resource.path("rest").path(PATH_AGE + age); 

        System.out.println("Client Response\n" 

                +getClientResponse(ageResource)); 

        System.out.println("Response\n" + getResponse(ageResource)); 

    } 

 

    /**

     * 返回客户端请求。 例如: GET

     *http://localhost:8080/RESTfulWS/rest/UserInfoService/name/Pavithra

     * 返回请求结果状态“200OK”。

     * 

     * @param service

     * @return

     */ 

    private static StringgetClientResponse(WebResource resource) { 

        returnresource.accept(MediaType.TEXT_XML).get(ClientResponse.class) 

                .toString(); 

    } 

 

    /**

     * 返回请求结果XML 例如:<User><Name>Pavithra</Name></User>

     * 

     * @param service

     * @return

     */ 

    private static StringgetResponse(WebResource resource) { 

        returnresource.accept(MediaType.TEXT_XML).get(String.class); 

    } 

}

调用结果:

 

 

4.2get方式还可以直接从浏览器直接调用

浏览器调用:

 

 

以上这些都是单纯的get方式提交的数据可使用

 

5.客户端调用我这有两种方式HttpURLConnection, HttpClient两种

5.1HttpURLConnection调用restful接口

代码如下:

package com.eviac.blog.restclient;

/****

 * 测试get请求方式,请求数据为单个参数,返回结果为json

 *get方法提交

 * 返回数据json

 */

import java.io.BufferedInputStream;

import java.io.BufferedReader;

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.PrintWriter;

import java.net.HttpURLConnection;

import java.net.MalformedURLException;

import java.net.URL;

 

public class JavaNetURLRESTFulClient {

        

         //post方式

          public static String postDownloadJson(Stringpath,String post){

                 URL url = null;

//接口的地址

                 path="http://localhost:8080/RestflService/rest/UserInfoService/userinfo";

//请求的参数

                post="id=\"{\"id\":\"11\"}\"";  

                 try {

                     url = new URL(path);

                     HttpURLConnection httpURLConnection= (HttpURLConnection) url.openConnection();

                     httpURLConnection.setRequestMethod("POST");//提交模式

                     // conn.setConnectTimeout(10000);//连接超时 单位毫秒

                     // conn.setReadTimeout(2000);//读取超时 单位毫秒

                     // 发送POST请求必须设置如下两行

                    httpURLConnection.setDoOutput(true);

                     httpURLConnection.setDoInput(true);

                    //httpURLConnection.setRequestProperty("Content-Type","application/json; charset=utf-8");

                     // 获取URLConnection对象对应的输出流

                     PrintWriter printWriter = newPrintWriter(httpURLConnection.getOutputStream());

                     // 发送请求参数

                     printWriter.write(post);//post的参数xx=xx&yy=yy

                     // flush输出流的缓冲

                     printWriter.flush();

                     //开始获取数据

                     BufferedInputStream bis = newBufferedInputStream(httpURLConnection.getInputStream());

                     ByteArrayOutputStream bos = newByteArrayOutputStream();

                     int len;

                     byte[] arr = new byte[1024];

                     while((len=bis.read(arr))!= -1){

                         bos.write(arr,0,len);

                         bos.flush();

                     }

                     bos.close();

                     returnbos.toString("utf-8");

                 } catch (Exception e) {

                     e.printStackTrace();

                 }

                 return null;

             }

      public static void main(String[] args) {

 

                try {

                         String id="123";

                         String targetURL ="http://localhost:8080/RestflService/rest/UserInfoService/userinfo/";

                         targetURL+=id;

                     URL restServiceURL = newURL(targetURL);

 

                     HttpURLConnectionhttpConnection = (HttpURLConnection) restServiceURL.openConnection();

                    httpConnection.setRequestMethod("GET");

                     //返回xml

                     //httpConnection.setRequestProperty("Content-Type","text/plain; charset=utf-8");

                     //返回json

                    httpConnection.setRequestProperty("Accept","application/json");

 

                     if(httpConnection.getResponseCode() != 200) {

                            throw newRuntimeException("HTTP GET Request Failed with Error code : "

                                          +httpConnection.getResponseCode());

                     }

 

                     BufferedReaderresponseBuffer = new BufferedReader(new InputStreamReader(

                           (httpConnection.getInputStream())));

 

                     String output;

                    System.out.println("Output from Server:  \n");

 

                     while ((output =responseBuffer.readLine()) != null) {

                           System.out.println(output);

                     }

 

                     //解析json

                    httpConnection.disconnect();

 

                } catch (MalformedURLExceptione) {

 

                     e.printStackTrace();

 

                } catch (IOException e) {

 

                     e.printStackTrace();

 

                }

 

              }

      

               // postDownloadJson(null,null);

      

}

5.2HttpClient调用restful接口(post & get方式)

代码如下:

package com.eviac.blog.restclient;

 

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

 

importorg.apache.commons.httpclient.HttpClient;

importorg.apache.commons.httpclient.HttpException;

importorg.apache.commons.httpclient.NameValuePair;

importorg.apache.commons.httpclient.methods.GetMethod;

importorg.apache.commons.httpclient.methods.PostMethod;

public class RestClient {

   public static void main(String[] args) {

       String urlpost ="http://localhost:8080/RestflService/rest/UserInfoService/user3info";

       String urlget ="http://localhost:8080/RestflService/rest/UserInfoService/name/1";

       HttpClient client = new HttpClient();

//POST方法

       GetMethod getmethod=new GetMethod(urlget);

       PostMethod method = new PostMethod(urlpost);

       NameValuePair[] data = {

                newNameValuePair("id","{\"id\":\"11\"}")};

       method.setRequestBody(data);

       try {

           int statusCode = client.executeMethod(method);

           if (statusCode == 200) {

              

                   

                    // String strJson =method.getResponseBodyAsString();

               // System.out.println("post方法="+strJson);

 

                BufferedReader reader = new BufferedReader(newInputStreamReader(method.getResponseBodyAsStream())); 

                StringBuffer stringBuffer = newStringBuffer(); 

                String str = ""; 

                while((str =reader.readLine())!=null){ 

                    stringBuffer.append(str); 

                } 

                String ts =stringBuffer.toString(); 

                System.out.println("post方法="+ts);

           }

       } catch (HttpException e) {

           e.printStackTrace();

       } catch (IOException e) {

           e.printStackTrace();

       }

       

       

     //执行get方法

       try {

           int statusCode = client.executeMethod(getmethod);

           if (statusCode == 200) {

                String strJson =getmethod.getResponseBodyAsString();

                System.out.println("get方法="+strJson);

               

                //System.out.println(map.get("user").getUsername());

           }

       } catch (HttpException e) {

           e.printStackTrace();

       } catch (IOException e) {

           e.printStackTrace();

       }

    }

   

 

}

 

5.3HttpURLConnection调用restful接口(post,多参数)

服务端方法配置:

//多参数测试 

   @POST

   //这里@Path定义了类的层次路径。指定了资源类提供服务的URI路径。 

   @Path("/user2info"

   // @Produces定义了资源类方法会生成的媒体类型

   //@Consumes(MediaType.APPLICATION_JSON) //json

   //多参数配置

   @Consumes({MediaType.MULTIPART_FORM_DATA,MediaType.APPLICATION_FORM_URLENCODED})

   @Produces(MediaType.APPLICATION_JSON//返回json

   // @PathParam@Path定义的表达式注入URI参数值。 

   publicString user2Json(@FormParam("id")

   String id,@FormParam("name") Stringname) {

     System.out.println(id);

     System.out.println(name);

        return"{\"name\":"+"\""+name+"\""+",\"age\":1,\"id\":"+"\""+id+"\"}";

 

客户端调用:代码

package com.eviac.blog.restclient;

importjava.io.BufferedInputStream;

importjava.io.BufferedReader;

importjava.io.ByteArrayOutputStream;

importjava.io.IOException;

importjava.io.InputStreamReader;

importjava.io.PrintWriter;

importjava.net.HttpURLConnection;

importjava.net.MalformedURLException;

importjava.net.URL;

/**

 *

 * @author Hanlong

 *  多参数配置

 *  请求数据为为多个参数

 *  返回结果是Json

 *  放在body体里

 *  Post方法提交

 */

public classTest2paras {

 

  //post方式

   publicstatic String postDownloadJson(String path,String post){

         URL url = null;

         path="http://localhost:8080/RestflService/rest/UserInfoService/user2info";

         post="{\"id\":\"11\"}\"";

         String post1="id=1&name=hanzl";

         try {

             url = new URL(path);

             HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();

             httpURLConnection.setRequestMethod("POST");// 提交模式

             // conn.setConnectTimeout(10000);//连接超时 单位毫秒

             // conn.setReadTimeout(2000);//读取超时 单位毫秒

             // 发送POST请求必须设置如下两行

             httpURLConnection.setDoOutput(true);

             httpURLConnection.setDoInput(true);

             //httpURLConnection.setRequestProperty("Content-Type","application/json; charset=utf-8");

             // 获取URLConnection对象对应的输出流

             PrintWriter printWriter = newPrintWriter(httpURLConnection.getOutputStream());

             // 发送请求参数

             printWriter.write(post1);//post的参数 xx=xx&yy=yy

             // flush输出流的缓冲

             printWriter.flush();

             //开始获取数据

             BufferedInputStream bis = newBufferedInputStream(httpURLConnection.getInputStream());

             ByteArrayOutputStream bos = new ByteArrayOutputStream();

             int len;

             byte[] arr = new byte[1024];

             while((len=bis.read(arr))!= -1){

                 bos.write(arr,0,len);

                 bos.flush();

             }

             bos.close();

             return bos.toString("utf-8");

         } catch (Exception e) {

             e.printStackTrace();

         }

         return null;

      }

       public static void main(String[] args) {

 

      System.out.println(postDownloadJson(null,null));

       }

}

5.4HttpURLConnection调用restful接口(post,参数为json,返回参数为json)

服务端

//多参数测试  参数为json

   @POST

   //这里@Path定义了类的层次路径。指定了资源类提供服务的URI路径。 

   @Path("/user3info"

   // @Produces定义了资源类方法会生成的媒体类型

   //@Consumes(MediaType.APPLICATION_JSON) //json

   //多参数配置

   @Consumes({MediaType.MULTIPART_FORM_DATA,MediaType.APPLICATION_FORM_URLENCODED})

   @Produces(MediaType.APPLICATION_JSON//返回json

   // @PathParam@Path定义的表达式注入URI参数值。 

   publicString user3Json(@FormParam("id")

   String id) {

     System.out.println(id);

        return"{\"name\":\"hanzl\",\"age\":1,\"id\":"+"\""+id+"\"}";

客户端代码

packagecom.eviac.blog.restclient;

importjava.io.BufferedInputStream;

importjava.io.BufferedReader;

importjava.io.ByteArrayOutputStream;

importjava.io.IOException;

importjava.io.InputStreamReader;

importjava.io.PrintWriter;

import java.net.HttpURLConnection;

importjava.net.MalformedURLException;

importjava.net.URL;

/**

 *

 * @author Hanlong

 *  多参数配置

 *  请求数据json

 *  返回结果是Json

 *  Post方法提交

 */

public classTestJsonparams {

     

      //post方式

       public static String postDownloadJson(Stringpath,String post){

             URL url = null;

             path="http://localhost:8080/RestflService/rest/UserInfoService/user3info";

             post="id={\"id\":\"11\"}\"";

             String post1=post;

             try {

                 url = new URL(path);

                 HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();

                 httpURLConnection.setRequestMethod("POST");// 提交模式

                 // conn.setConnectTimeout(10000);//连接超时 单位毫秒

                 // conn.setReadTimeout(2000);//读取超时 单位毫秒

                 // 发送POST请求必须设置如下两行

                 httpURLConnection.setDoOutput(true);

                 httpURLConnection.setDoInput(true);

                 //httpURLConnection.setRequestProperty("Content-Type","application/json; charset=utf-8");

                 // 获取URLConnection对象对应的输出流

                 PrintWriter printWriter = newPrintWriter(httpURLConnection.getOutputStream());

                 // 发送请求参数

                 printWriter.write(post1);//post的参数 xx=xx&yy=yy

                 // flush输出流的缓冲

                 printWriter.flush();

                 //开始获取数据

                 BufferedInputStream bis = newBufferedInputStream(httpURLConnection.getInputStream());

                 ByteArrayOutputStream bos = new ByteArrayOutputStream();

                 int len;

                 byte[] arr = new byte[1024];

                 while((len=bis.read(arr))!= -1){

                      bos.write(arr,0,len);

                      bos.flush();

                 }

                 bos.close();

                 return bos.toString("utf-8");

             } catch (Exception e) {

                 e.printStackTrace();

             }

             return null;

         }

       public static void main(String[] args) {

 

              

      

            System.out.println(postDownloadJson(null,null));

       }

}

 

 

6.项目完整包(附件带jar包)

https://download.csdn.net/download/hanzl1/10490670https://download.csdn.net/download/hanzl1/10490670

 

https://wenku.baidu.com/view/7a0cc78b846a561252d380eb6294dd88d0d23ddc

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

restful接口客户端和服务端开发,HttpURLConnection,HttpClient,post ,get方式调用 的相关文章

随机推荐

  • Elasticsearch安装ik分词插件

    前置条件 如果发现问题请留言 如果有发现不正确的地方 欢迎留言指正 感激不尽 已安装好Elasticsearch 本次安装插件版本为7 3 1 需与elasticsearch版本一致 elasticsearch安装在 home elk el
  • Fluid主题出错解决方案

    Fluid主题排版出错 重装一次主题解决 一 存在问题 大半个月没有浏览Hexo博客 再次浏览的时候发现网页的排版布局竟然出错了 PS 导航栏排版出错 PS 内容板块的宽度失效 PS footer部分排版也出错了 打开 开发者模式 查看一下
  • k8s远程debug

    k8s远程debug 1 方案1 方案1是不行的 因为k8s的ingress走的7层协议 1 1 应用 启动debug端口 java agentlib jdwp transport dt socket server y suspend n
  • PCL点云处理之添加高斯噪点的两种方法(详细注释版)(一百八十一)

    PCL点云处理之添加高斯噪点的两种方法 详细注释版 一百八十一 一 实验效果 二 算法简介 三 具体流程 四 PCL自带函数实现 1 代码 2 结果 五 Boost函数实现 1 代码 2 结果 总结 一 实验效果 通过实验测试 效果如上所示
  • java usb camera_android4.0 USB Camera实例(一)HAL层

    一直想自己写一个从HAL层到应用层的Camera例子 android4 0上usb camera用不了 所以决定自己写一个 usb camera和coms原理都是一样的 基本v4l2 只不过源码数据格式不一样而已 下面我们就从HAL层开始
  • IDEA在包下右键new没有Servlet选项?解决办法

    在包下右键没有new一个Servlet 1 首先检查pom xml文件中Tomcat和Servlet的坐标有没有导入 Tomcat坐标
  • Ubuntu安装psycopg2小记

    作者 Wally Yu 在windows上和Linux上安装psycopg2都遇到了点小插曲 记录如下 Windows下 1 前往官网下载源代码 http www initd org psycopg 2 解压 3 运行python setu
  • Docker-容器

    Docker的应用场景 Web 应用的自动化打包和发布 自动化测试和持续集成 发布 在服务型环境中部署和调整数据库或其他的后台应用 Docker的架构 Docker 镜像 Images Docker 镜像是用于创建 Docker 容器的模板
  • taro 支付宝/微信小程序的chooseImage真机和开发工具上的区别

    支付宝小程序 微信小程序
  • 创建Win PE启动盘(小白都会装系统)

    第一步 下载启动盘制作软件 打开搜索引擎 搜索 电脑店 找到下图链接 打开电脑店网站如下图所示 然后点击 完整版下载 开始下载制作PE系统的软件 下载完成后解压到当前目录 如下图 打开后 找到DianNaoDian exe文件双击打开 第二
  • 关于IDEA在创建Maven子模块后的pom.xml文件没有parent标签的解决方法。

    关于IDEA在创建Maven子模块后的pom xml文件没有parent标签的解决方法 问题 我们在创建Maven子模块后的pom xml文件一开始是有parent标签的 然后加载完就直接消失了 解决方法 直接手打上去 具体格式网上都有说怎
  • SQL Server(MMS)开启代理服务器(agent)方法(本篇版本展示界面为SQLserver2014)

    第一步 在SQL Server Management Studio中连接到SQL Server实例后 会显示 SQL Server 代理 节点 如果当前该实例的Agent服务没有启动 SQL Server 代理 后边就会显示 已禁用代理XP
  • libcurl库及curl API的简介

    目录 一 libcurl简介 二 curl API简介 三 库安装编译方法 内容来源 Http协议之libcurl实现 谢呈勖 博客园 cnblogs com 一 libcurl简介 libcurl是一个跨平台的网络协议库 支持http h
  • JAVA Eclipse连接SQL Server 2019并从数据库中读取表中数据

    一 进入SQL Server 配置登录名和密码 这里有默认的sa 一开始是禁用的 选中sa 右键 属性 1 授予and启用 2 设置登录名和密码 点击确定 然后关闭SQL 重新进入的时候身份验证选择SQL Server身份验证 二 新建一个
  • maven 配置多镜像

    1 配置maven的setting xml
  • Activity之任务和返回栈

    一个应用程序中会有多个activity 每个activity一般都有自己独立的功能 我们可以用activity启动自己应用中的另一个activity 例如 从一个数据列表界面 跳转到一个数据详情界面 也可以用我们的activity去打开其他
  • 深入理解javascript对象

    理解对象 对象被定义为一组属性的无序集合 对象就是一组没有特定顺序的值 对象的每个value值都由一个key来标识 一个key映射一个value值 1 Object 创建对象 创建了一个名为 person 的对象 而且有三个属性 name
  • Android adb实现原理

    adb定义 adb Android Debug Bridge 安卓调试桥 包含adb client adb server和adbd三部分 adb client 运行在PC上 即DDMS或者在Windows dos下启动的adb shell
  • Mysql Connector/J 源码分析(Failover)

    文章目录 前言 一 什么是Failover 二 Failover的主要结构 三 异常处理 3 1 构造连接阶段 小结 3 2 使用连接阶段 小结 四 四元素判定 小结 五 专有选择项 六 官网的态度 总结 前言 本文讨论Connector
  • restful接口客户端和服务端开发,HttpURLConnection,HttpClient,post ,get方式调用

    Restful服务端及客户端调用实例 1 新建web工程作为服务端 创建服务端代码 前情提示 GET SELECT 从服务器取出资源 一项或多项 POST CREATE 在服务器新建一个资源 PUT UPDATE 在服务器更新资源 客户端提