核心逻辑
绕过ssl证书检查
具体操作
话不多说上代码
// 构建WebClient
public static WebClient createWebClient() throws SSLException {
SslContext context = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
HttpClient httpClient = HttpClient.create().secure(t -> t.sslContext(context));
return WebClient.builder().clientConnector(new ReactorClientHttpConnector(httpClient)).build();
相关import
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.netty.http.client.HttpClient;
import javax.net.ssl.SSLException;
具体使用
使用createWebClient()方法来构建WebClient进行SDK调用即可。
WebClient webClient = xxxx.createWebClient();
webClient.post()…
webClient.get()…