赞
踩
申请方式:跳转HanLP秘钥申请步骤
<!--hanlp自然语言处理技术依赖-->
<dependency>
<groupId>com.hankcs.hanlp.restful</groupId>
<artifactId>hanlp-restful</artifactId>
<version>0.0.12</version>
</dependency>
import com.hankcs.hanlp.restful.HanLPClient; /** * @author wangghua * @ClassName HanlpMain * @描述: Hanlp语义文本主类 * @datetime 2023年 01月 04日 17:14 */ public class HanlpMain { public static void main(String[] args) throws Exception{ // SslUtils.ignoreSsl();//信任网站证书 HanLPClient client = new HanLPClient("https://www.hanlp.com/api", "你申请到的秘钥"); //第二个参数秘钥,需要申请 System.out.println(client.grammaticalErrorCorrection("年轻人要有报复和理想,为国家离异而奋斗"));//文本纠错 //client.grammaticalErrorCorrection()是文本纠错的方法 } }
import javax.net.ssl.*; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; /** * @author wangghua * @ClassName SslUtils * @描述: * @datetime 2023年 01月 05日 9:17 */ public class SslUtils { private static void trustAllHttpsCertificates() throws Exception { TrustManager[] trustAllCerts = new TrustManager[1]; TrustManager tm = new miTM(); trustAllCerts[0] = tm; SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, null); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } static class miTM implements TrustManager, X509TrustManager { public X509Certificate[] getAcceptedIssuers() { return null; } public boolean isServerTrusted(X509Certificate[] certs) { return true; } public boolean isClientTrusted(X509Certificate[] certs) { return true; } public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException { return; } public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException { return; } } /** * 忽略HTTPS请求的SSL证书,必须在openConnection之前调用 * @throws Exception */ public static void ignoreSsl() throws Exception{ HostnameVerifier hv = new HostnameVerifier() { public boolean verify(String urlHostName, SSLSession session) { System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost()); return true; } }; trustAllHttpsCertificates(); HttpsURLConnection.setDefaultHostnameVerifier(hv); } }
SslUtils.ignoreSsl();//信任网站证书
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。