Netty实现SSL双向验证完整实例
一、证书准备
要使用ssl双向验证,就必须先要生成服务端和客户端的证书,并相互添加信任,具体流程如下(本人调试这个用例的时候,花了很多时间来验证证书是否正确,以及握手失败的原因,这里证书生成过程只要按流程走,本人能保证绝对没有问题)
现在打开cmd,在哪个目录下打开,证书就会放在哪个目录下:
第一步: 生成Netty服务端私钥和证书仓库命令
keytool -genkey -alias securechat -keysize 2048 -validity 365 -keyalg RSA -dname "CN=localhost" -keypass sNetty -storepass sNetty -keystore sChat.jks
- -keysize 2048 密钥长度2048位(这个长度的密钥目前可认为无法被暴力破解)
- -validity 365 证书有效期365天
- -keyalg RSA 使用RSA非对称加密算法
- -dname "CN=localhost" 设置Common Name为localhost
- -keypass sNetty密钥的访问密码为sNetty
- -storepass sNetty密钥库的访问密码为sNetty(其实这两个密码也可以设置一样,通常都设置一样,方便记)
- -keystore sChat.jks 指定生成的密钥库文件为sChata.jks
第二步:生成Netty服务端自签名证书
keytool -export -alias securechat -keystore sChat.jks -storepass sNetty -file sChat.cer
第三步:生成客户端的密钥对和证书仓库,用于将服务端的证书保存到客户端的授信证书仓库中
keytool -genkey -alias smcc -keysize 2048 -validity 365 -keyalg RSA -dname "CN=localhost" -keypass sNetty -storepass sNetty -keystore cChat.jks
第四步:将Netty服务端证书导入到客户端的证书仓库中
keytool -import -trustcacerts -alias securechat -file sChat.cer -storepass sNetty -keystore cChat.jks
如果你只做单向认证,则到此就可以结束了,如果是双响认证,则还需继续往下走
第五步:生成客户端自签名证书
keytool -export -alias smcc -keystore cChat.jks -storepass sNetty -file cChat.cer
最后一步:将客户端的自签名证书导入到服务端的信任证书仓库中:
keytool -import -trustcacerts -alias smcc -file cChat.cer -storepass sNetty -keystore sChat.jks
到这里,证书就生成完毕了,我们就可以得到两个jks文件,一个是服务端的sChat.jks ,一个是客户端的cChat.jks ,这两个文件后面初始化sslCOntext的时候会用到
如果还想了解更多可以查看
http://dwj147258.iteye.com/blog/2339934
二、netty服务端
下面就直接贴代码了,首先是实例化SSLContext的类:
- package main.java.com.nionetty;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.security.KeyStore;
- import java.security.NoSuchAlgorithmException;
- import javax.net.ssl.KeyManager;
- import javax.net.ssl.KeyManagerFactory;
- import javax.net.ssl.SSLContext;
- import javax.net.ssl.TrustManager;
- import javax.net.ssl.TrustManagerFactory;
- import org.springframework.core.io.ClassPathResource;
- /**
- * 初始化sslcontext类
- *
- */
- public class ContextSSLFactory {
- private static final SSLContext SSL_CONTEXT_S ;
- private static final SSLContext SSL_CONTEXT_C ;
- static{
- SSLContext sslContext = null ;
- SSLContext sslContext2 = null ;
- try {
- sslContext = SSLContext.getInstance("SSLv3") ;
- sslContext2 = SSLContext.getInstance("SSLv3") ;
- } catch (NoSuchAlgorithmException e1) {
- e1.printStackTrace();
- }
- try{
- if(getKeyManagersServer() != null && getTrustManagersServer() != null ){
- sslContext.init(getKeyManagersServer(), getTrustManagersServer(), null);
- }
- if(getKeyManagersClient() != null && getTrustManagersClient() != null){
- sslContext2.init(getKeyManagersClient(), getTrustManagersClient(), null);
- }
- }catch(Exception e){
- e.printStackTrace() ;
- }
- sslContext.createSSLEngine().getSupportedCipherSuites() ;
- sslContext2.createSSLEngine().getSupportedCipherSuites() ;
- SSL_CONTEXT_S = sslContext ;
- SSL_CONTEXT_C = sslContext2 ;
- }
- public ContextSSLFactory(){
- }
- public static SSLContext getSslContext(){
- return SSL_CONTEXT_S ;
- }
- public static SSLContext getSslContext2(){
- return SSL_CONTEXT_C ;
- }
- private static TrustManager[] getTrustManagersServer(){
- FileInputStream is = null ;
- KeyStore ks = null ;
- TrustManagerFactory keyFac = null ;
- TrustManager[] kms = null ;
- try {
- // 获得KeyManagerFactory对象. 初始化位默认算法
- keyFac = TrustManagerFactory.getInstance("SunX509") ;
- is =new FileInputStream( (new ClassPathResource("main/java/conf/sChat.jks")).getFile() );
- ks = KeyStore.getInstance("JKS") ;
- String keyStorePass = "sNetty" ;
- ks.load(is , keyStorePass.toCharArray()) ;
- keyFac.init(ks) ;
- kms = keyFac.getTrustManagers() ;
- } catch (Exception e) {
- e.printStackTrace();
- }
- finally{
- if(is != null ){
- try {
- is.close() ;
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return kms ;
- }
- private static TrustManager[] getTrustManagersClient(){
- FileInputStream is = null ;
- KeyStore ks = null ;
- TrustManagerFactory keyFac = null ;
- TrustManager[] kms = null ;
- try {
- // 获得KeyManagerFactory对象. 初始化位默认算法
- keyFac = TrustManagerFactory.getInstance("SunX509") ;
- is =new FileInputStream( (new ClassPathResource("main/java/conf/cChat.jks")).getFile() );
- ks = KeyStore.getInstance("JKS") ;
- String keyStorePass = "sNetty" ;
- ks.load(is , keyStorePass.toCharArray()) ;
- keyFac.init(ks) ;
- kms = keyFac.getTrustManagers() ;
- } catch (Exception e) {
- e.printStackTrace();
- }
- finally{
- if(is != null ){
- try {
- is.close() ;
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return kms ;
- }
- private static KeyManager[] getKeyManagersServer(){
- FileInputStream is = null ;
- KeyStore ks = null ;
- KeyManagerFactory keyFac = null ;
- KeyManager[] kms = null ;
- try {
- // 获得KeyManagerFactory对象. 初始化位默认算法
- keyFac = KeyManagerFactory.getInstance("SunX509") ;
- is =new FileInputStream( (new ClassPathResource("main/java/conf/sChat.jks")).getFile() );
- ks = KeyStore.getInstance("JKS") ;
- String keyStorePass = "sNetty" ;
- ks.load(is , keyStorePass.toCharArray()) ;
- keyFac.init(ks, keyStorePass.toCharArray()) ;
- kms = keyFac.getKeyManagers() ;
- } catch (Exception e) {
- e.printStackTrace();
- }
- finally{
- if(is != null ){
- try {
- is.close() ;
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return kms ;
- }
- private static KeyManager[] getKeyManagersClient(){
- FileInputStream is = null ;
- KeyStore ks = null ;
- KeyManagerFactory keyFac = null ;
- KeyManager[] kms = null ;
- try {
- // 获得KeyManagerFactory对象. 初始化位默认算法
- keyFac = KeyManagerFactory.getInstance("SunX509") ;
- is =new FileInputStream( (new ClassPathResource("main/java/conf/cChat.jks")).getFile() );
- ks = KeyStore.getInstance("JKS") ;
- String keyStorePass = "sNetty" ;
- ks.load(is , keyStorePass.toCharArray()) ;
- keyFac.init(ks, keyStorePass.toCharArray()) ;
- kms = keyFac.getKeyManagers() ;
- } catch (Exception e) {
- e.printStackTrace();
- }
- finally{
- if(is != null ){
- try {
- is.close() ;
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return kms ;
- }
- }
服务端启动类:
- package main.java.com.nionetty;
- import javax.net.ssl.SSLEngine;
- import javax.print.attribute.standard.MediaSize.Engineering;
- import main.java.com.nettyTest.SecureChatServerHandler;
- import io.netty.bootstrap.ServerBootstrap;
- import io.netty.channel.ChannelHandlerContext;
- import io.netty.channel.ChannelInitializer;
- import io.netty.channel.ChannelOption;
- import io.netty.channel.ChannelPipeline;
- import io.netty.channel.EventLoopGroup;
- import io.netty.channel.nio.NioEventLoopGroup;
- import io.netty.channel.socket.SocketChannel;
- import io.netty.channel.socket.nio.NioServerSocketChannel;
- import io.netty.handler.logging.LogLevel;
- import io.netty.handler.logging.LoggingHandler;
- import io.netty.handler.ssl.SslHandler;
- import io.netty.handler.timeout.IdleState;
- import io.netty.handler.timeout.IdleStateEvent;
- import io.netty.handler.timeout.IdleStateHandler;
- public class NettySocketServer {
- private static SslHandler sslHandler = null ;
- private EventLoopGroup bossGroup = null ;
- private EventLoopGroup workerGroup = null ;
- public void start(){
- bossGroup = new NioEventLoopGroup() ;
- workerGroup = new NioEventLoopGroup() ;
- try{
- ServerBootstrap serverStrap = new ServerBootstrap() ;
- serverStrap.group(bossGroup , workerGroup)
- .channel(NioServerSocketChannel.class)
- .option(ChannelOption.SO_BACKLOG, 128)
- .option(ChannelOption.SO_KEEPALIVE, true)
- .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000 * 5 * 60)
- .handler(new LoggingHandler(LogLevel.DEBUG))
- .childHandler(new ChannelInitializer<SocketChannel>() {
- @Override
- protected void initChannel(SocketChannel socketChannel) throws Exception {
- ChannelPipeline pie = socketChannel.pipeline() ;
- pie.addLast("decoder" , new MyDecoder()) ;
- pie.addLast("encoder" , new MyEncoder()) ;
- pie.addLast("handler" , new NettySocketSSLHandler()) ;
- SSLEngine engine = ContextSSLFactory.getSslContext().createSSLEngine();
- engine.setUseClientMode(false);
- engine.setNeedClientAuth(true);
- pie.addFirst("ssl", new SslHandler(engine));
- }
- });
- serverStrap.bind(161616).sync() ;
- System.out.println("服务已开启");
- }catch(Exception e){
- e.printStackTrace() ;
- bossGroup.shutdownGracefully() ;
- workerGroup.shutdownGracefully() ;
- }
- }
- private SslHandler getSslHandler(){
- if(sslHandler == null ){
- SSLEngine sslEngine = ContextSSLFactory.getSslContext().createSSLEngine() ;
- sslEngine.setUseClientMode(false) ;
- //false为单向认证,true为双向认证
- sslEngine.setNeedClientAuth(true) ;
- sslHandler = new SslHandler(sslEngine);
- }
- return sslHandler ;
- }
- public static void main(String[] args) {
- new NettySocketServer().start() ;
- }
- }
编码器:
- package main.java.com.nionetty;
- import io.netty.buffer.ByteBuf;
- import io.netty.channel.ChannelHandlerContext;
- import io.netty.handler.codec.MessageToByteEncoder;
- import java.nio.ByteBuffer;
- public class MyEncoder extends MessageToByteEncoder<ByteBuffer>{
- @Override
- protected void encode(ChannelHandlerContext ctx, ByteBuffer message,
- ByteBuf out) throws Exception {
- if(message==null){
- return;
- }
- if(message.hasArray()){
- byte[] msg =message.array();
- if(msg == null || msg.length <= 0){
- return;
- }
- out.writeBytes(msg) ;
- }
- }
- }
解码器:
- /*
- * Copyright (C) TD Tech<br>
- * All Rights Reserved.<br>
- *
- */
- package main.java.com.nionetty;
- import io.netty.buffer.ByteBuf;
- import io.netty.channel.ChannelHandlerContext;
- import io.netty.handler.codec.ByteToMessageDecoder;
- import java.nio.ByteBuffer;
- import java.util.List;
- /**
- * Create Date: 2014-11-4 下午02:42:21<br>
- * Create Author: lWX232692<br>
- * Description :
- */
- public class MyDecoder extends ByteToMessageDecoder {
- @Override
- protected void decode(ChannelHandlerContext ctx, ByteBuf buffer,
- List<Object> out) throws Exception {
- //UnpooledUnsafeDirectByteBuf(ridx: 0, widx: 1, cap: 1024)
- if (buffer != null) {
- ByteBuffer msg = null;
- try {
- if(buffer.readableBytes() > 0 ){
- msg = ByteBuffer.allocate(buffer.readableBytes()) ;
- byte[] bb = new byte[buffer.readableBytes()] ;
- buffer.readBytes(bb) ;
- msg.put(bb);
- msg.flip();
- }
- } catch (Exception e) {
- e.printStackTrace();
- msg = null ;
- }
- if (msg != null) {
- out.add(msg);
- }
- }
- }
- }
业务实现类:
- package main.java.com.nionetty;
- import io.netty.channel.Channel;
- import io.netty.channel.ChannelHandlerContext;
- import io.netty.channel.SimpleChannelInboundHandler;
- import io.netty.handler.ssl.SslHandler;
- import io.netty.util.concurrent.Future;
- import io.netty.util.concurrent.GenericFutureListener;
- import java.net.InetAddress;
- import java.nio.ByteBuffer;
- import java.util.Arrays;
- public class NettySocketSSLHandler extends SimpleChannelInboundHandler<ByteBuffer>{
- @Override
- public void channelActive(final ChannelHandlerContext ctx) throws Exception {
- // Once session is secured, send a greeting and register the channel to the global channel
- // list so the channel received the messages from others.
- ctx.pipeline().get(SslHandler.class).handshakeFuture().addListener(
- new GenericFutureListener<Future<Channel>>() {
- @Override
- public void operationComplete(Future<Channel> future) throws Exception {
- if(future.isSuccess()){
- System.out.println("握手成功");
- byte[] array = new byte[]{ (byte)7d, 04} ;
- ByteBuffer bu = ByteBuffer.wrap(array) ;
- ctx.channel().writeAndFlush(bu) ;
- }else{
- System.out.println("握手失败");
- }
- ctx.writeAndFlush(
- "Welcome to " + InetAddress.getLocalHost().getHostName() +
- " secure chat service!\n");
- ctx.writeAndFlush(
- "Your session is protected by " +
- ctx.pipeline().get(SslHandler.class).engine().getSession().getCipherSuite() +
- " cipher suite.\n");
- }
- });
- }
- @Override
- public void handlerAdded(ChannelHandlerContext ctx)
- throws Exception {
- System.out.println("服务端增加");
- }
- @Override
- public void handlerRemoved(ChannelHandlerContext ctx){
- System.out.println("移除:"+ctx.channel().remoteAddress());
- }
- @Override
- public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
- System.out.println("Unexpected exception from downstream.");
- ctx.close();
- }
- @Override
- public void messageReceived(ChannelHandlerContext ctx, ByteBuffer msg) throws Exception {
- System.out.println("服务端receive msg ");
- byte[] array = new byte[]{00, 01, 00, 00, 00, 06, 05, 03, (byte)7d, 00, 00, 07} ;
- ByteBuffer bu = ByteBuffer.wrap(array) ;
- ctx.channel().writeAndFlush(bu) ;
- }
- }
三、客户端
客户端实现类
- package main.java.com.nionetty.client;
- import java.net.InetSocketAddress;
- import java.net.SocketAddress;
- import javax.net.ssl.SSLEngine;
- import io.netty.bootstrap.Bootstrap;
- import io.netty.channel.Channel;
- import io.netty.channel.ChannelFuture;
- import io.netty.channel.ChannelInitializer;
- import io.netty.channel.ChannelOption;
- import io.netty.channel.ChannelPipeline;
- import io.netty.channel.EventLoopGroup;
- import io.netty.channel.nio.NioEventLoopGroup;
- import io.netty.channel.socket.SocketChannel;
- import io.netty.channel.socket.nio.NioSocketChannel;
- import io.netty.handler.ssl.SslHandler;
- import main.java.com.nionetty.ContextSSLFactory;
- import main.java.com.nionetty.MyDecoder;
- import main.java.com.nionetty.MyEncoder;
- public class NettySocketClient {
- private EventLoopGroup group ;
- private Channel channel = null ;
- public void connect(String ip , int port){
- group = new NioEventLoopGroup();
- try{
- Bootstrap strap = new Bootstrap();
- strap.group(group)
- .channel(NioSocketChannel.class)
- .option(ChannelOption.TCP_NODELAY, true)
- .option(ChannelOption.SO_KEEPALIVE , true)
- .handler(new ChannelInitializer<SocketChannel>() {
- @Override
- protected void initChannel(SocketChannel socketChannel) throws Exception {
- ChannelPipeline pieple = socketChannel.pipeline() ;
- pieple.addLast("decoder" , new MyClientDecoder()) ;
- pieple.addLast("encoder" , new MyClientEncoder()) ;
- pieple.addLast("handler" , new NettySocketSSLClientHandler()) ;
- SSLEngine engine = ContextSSLFactory.getSslContext2().createSSLEngine();
- engine.setUseClientMode(true);
- pieple.addFirst("ssl", new SslHandler(engine));
- }
- });
- SocketAddress address = new InetSocketAddress(ip, port);
- final ChannelFuture future = strap.connect(address).sync();
- channel = future.awaitUninterruptibly().channel();
- System.out.println("连接成功, channel =" + channel.remoteAddress());
- }catch(Exception e ){
- e.printStackTrace();
- group.shutdownGracefully() ;
- }finally{
- }
- }
- private static SslHandler sslHandlerClient = null ;
- public static SslHandler getSslHandler(){
- if(sslHandlerClient == null){
- SSLEngine sslEngine = ContextSSLFactory.getSslContext2().createSSLEngine() ;
- sslEngine.setUseClientMode(true) ;
- sslHandlerClient = new SslHandler(sslEngine);
- }
- return sslHandlerClient ;
- }
- public static void main(String[] args) {
- new NettySocketClient().connect("192.168.10.256", 161616) ;
- }
- }
编码器:
- package main.java.com.nionetty.client;
- import io.netty.buffer.ByteBuf;
- import io.netty.channel.ChannelHandlerContext;
- import io.netty.handler.codec.MessageToByteEncoder;
- import java.nio.ByteBuffer;
- public class MyClientEncoder extends MessageToByteEncoder<ByteBuffer>{
- @Override
- protected void encode(ChannelHandlerContext ctx, ByteBuffer message,
- ByteBuf out) throws Exception {
- if(message==null){
- return;
- }
- if(message .hasArray()){
- byte[] msg =message.array();
- if(msg == null || msg.length <= 0){
- return;
- }
- out.writeBytes(msg);
- }
- }
- }
解码器:
- /*
- * Copyright (C) TD Tech<br>
- * All Rights Reserved.<br>
- *
- */
- package main.java.com.nionetty.client;
- import io.netty.buffer.ByteBuf;
- import io.netty.channel.ChannelHandlerContext;
- import io.netty.handler.codec.ByteToMessageDecoder;
- import java.nio.ByteBuffer;
- import java.util.List;
- /**
- * Create Date: 2014-11-4 下午02:42:21<br>
- * Create Author: lWX232692<br>
- * Description :
- */
- public class MyClientDecoder extends ByteToMessageDecoder {
- @Override
- protected void decode(ChannelHandlerContext ctx, ByteBuf buffer,
- List<Object> out) throws Exception {
- //UnpooledUnsafeDirectByteBuf(ridx: 0, widx: 1, cap: 1024)
- if (buffer != null) {
- ByteBuffer msg = null;
- try {
- if(buffer.readableBytes() > 0 ){
- msg = ByteBuffer.allocate(buffer.readableBytes()) ;
- byte[] bb = new byte[buffer.readableBytes()] ;
- buffer.readBytes(bb) ;
- msg.put(bb);
- msg.flip();
- }
- } catch (Exception e) {
- e.printStackTrace();
- msg = null ;
- }
- if (msg != null) {
- out.add(msg);
- }
- }
- }
- }
业务handler:
- /*
- * Copyright (C) TD Tech<br>
- * All Rights Reserved.<br>
- *
- */
- package main.java.com.nionetty.client;
- import io.netty.buffer.ByteBuf;
- import io.netty.channel.ChannelHandlerContext;
- import io.netty.handler.codec.ByteToMessageDecoder;
- import java.nio.ByteBuffer;
- import java.util.List;
- /**
- * Create Date: 2014-11-4 下午02:42:21<br>
- * Create Author: lWX232692<br>
- * Description :
- */
- public class MyClientDecoder extends ByteToMessageDecoder {
- @Override
- protected void decode(ChannelHandlerContext ctx, ByteBuf buffer,
- List<Object> out) throws Exception {
- //UnpooledUnsafeDirectByteBuf(ridx: 0, widx: 1, cap: 1024)
- if (buffer != null) {
- ByteBuffer msg = null;
- try {
- if(buffer.readableBytes() > 0 ){
- msg = ByteBuffer.allocate(buffer.readableBytes()) ;
- byte[] bb = new byte[buffer.readableBytes()] ;
- buffer.readBytes(bb) ;
- msg.put(bb);
- msg.flip();
- }
- } catch (Exception e) {
- e.printStackTrace();
- msg = null ;
- }
- if (msg != null) {
- out.add(msg);
- }
- }
- }
- }
测试通过,搞了因为在网上没有找到完整的实例,所以因为一个小问题,找了两天都没有找到原因,希望看到的同学能够有所收获
Netty实现SSL双向验证完整实例的更多相关文章
- 请给你的短信验证码接口加上SSL双向验证
序言 去年年底闲来几天,有位同事专门在网上找一些注册型的app和网站,研究其短信接口是否安全,半天下来找到30来家,一些短信接口由于分析难度原因,没有继续深入,但差不多挖掘到20来个,可以肆意被调用, ...
- MQTT研究之EMQ:【SSL双向验证】
EMQ是当前MQTT中,用于物联网领域中比较出色的一个broker,今天我这里要记录和分享的是关于SSL安全通信的配置和注意细节. 环境: 1. 单台Linux CentOS7.2系统,安装一个EMQ ...
- nginx配置ssl双向验证 nginx https ssl证书配置
1.安装nginx 参考<nginx安装>:http://www.ttlsa.com/nginx/nginx-install-on-linux/ 如果你想在单IP/服务器上配置多个http ...
- Struts2的手工自定义验证--完整实例代码
ActionSupport类实现了Validateable.ValidationAware接口, 其中Validateable接口就是验证器接口,该接口有一个validate()方法, validat ...
- MQTT研究之EMQ:【SSL证书链验证】
1. 创建证书链(shell脚本) 客户端证书链关系: rootCA-->chainca1-->chainca2-->chainca3 ca caCert1 caCert2 caCe ...
- netty集成ssl完整参考指南(含完整源码)
虽然我们在内部rpc通信中使用的是基于认证和报文头加密的方式实现安全性,但是有些时候仍然需要使用SSL加密,可能是因为对接的三方系统需要,也可能是由于open的考虑.中午特地测了下netty下集成ss ...
- 前后端API交互数据加密——AES与RSA混合加密完整实例
前言 前段时间看到一篇文章讲如何保证API调用时数据的安全性(传送门:https://blog.csdn.net/ityouknow/article/details/80603617),文中讲到利用R ...
- SSL 通信原理及Tomcat SSL 双向配置
SSL 通信原理及Tomcat SSL 双向配置 目录1 参考资料 .................................................................. ...
- Https双向验证与Springboot整合测试-人来人往我只认你
1 简介 不知不觉Https相关的文章已经写了6篇了,本文将是这个专题的最后一篇,起码近期是最后一篇.前面6篇讲的全都是单向的Https验证,本文将重点介绍一下双向验证.有兴趣的同学可以了解一下之前的 ...
随机推荐
- Kotlin注解深入解析与实例剖析
在上一次https://www.cnblogs.com/webor2006/p/11522798.html中学习了Kotlin注解相关的东东,这次继续对Kotlin的注解继续学习: 注解也可以拥有自己 ...
- 用python+openpyxl从表格中读取测试用例的多条数据,然后将执行结果写入表格中
# -*- coding: utf-8 -*- from selenium import webdriver from openpyxl import load_workbook class mylo ...
- c++查询特定字符串位置
size_t find (const string& str, size_t pos = 0) const noexcept;(摘自c++官网:std::string::find) size_ ...
- httpclient post请求中文乱码解决办法
在使用httpclient发送post请求的时候,接收端中文乱码问题解决. 正文: 我们都知道,一般情况下使用post请求是不会出现中文乱码的.可是在使用httpclient发送post请求报文含中文 ...
- strtok在keil中使用小笔记及字符串转换为多个浮点数的方法
在pc上面使用这个字符串函数,是没有问题的,但是我在keil中结合rtos来处理字符串的时候,比如char *s = "1.01313;17.2609;17.4875";那么就只能 ...
- Tips on Acoustic Signal Processing
1.声音的三个主要的主观属性(即音量.音调.音色).音色(Timbre)是指不同的声音的频率表现在波形方面总是有与众不同的特性,音色的不同取决于不同的泛音.频率的高低决定声音的音调,振幅的大小决定声音 ...
- gin内置验证器使用
gin内置验证器使用 func TopicUrl(f1 validator.FieldLevel) bool { return true //返回true表示验证成功 } func main(){ r ...
- 洛谷 P3388 【模板】割点(割顶)题解
今天学了割点,就A了这道板子,比较难理解的地方就在于如果是根节点就要找两个点来满足low[y]>=dfn[x],如果不是就只需找一个点来满足.Tarjan(i,i)中第一个i是开始搜索的点而第 ...
- 微信小程序底部导航栏部署
在微信小程序开发app.json(app.json它是定义全局页面) 只是用来部署微信底部的图标,最多不能大于五个 "tabBar":{ "selectedColor&q ...
- /proc/pid/statm content analysis
root@am335x-ec:/# cat /proc/1/statm 6141 1181 699 232 0 4641 0 Table 1-3: Contents of the statm file ...