重庆 机械有限公司 沙坪坝网站建设wordpress设置恢复
news/
2025/9/29 7:58:00/
文章来源:
重庆 机械有限公司 沙坪坝网站建设,wordpress设置恢复,怎么入驻电商平台,秦皇岛网站制作报价本文主要用于工作记录#xff0c;在项目中遇到了就记录一下
在早期#xff0c;原生的JDK8是不支持HTTP/2协议的#xff0c;所以#xff0c;要想使用这个特性#xff0c;需要有web服务器和应用环境的支持#xff0c; 例如#xff1a;在VM中增加-Xbootclasspath/p:/Users…本文主要用于工作记录在项目中遇到了就记录一下
在早期原生的JDK8是不支持HTTP/2协议的所以要想使用这个特性需要有web服务器和应用环境的支持 例如在VM中增加-Xbootclasspath/p:/Users/a1234/Downloads/alpn-boot-8.1.11.v20170118.jar来配合使用 但是从8u252开始ALPN层已经从Java 11向后移植到了Java 8。意味着只要使用Java 8u252或更新版本不再要求使用Conscrypt和Jetty就可以使用HTTP/2了。 重点来了一定要先检查自己的jdk版本是否大于8u252然后就可以在项目中集成okhttp 项目pom配置
!-- SpringBoot 依赖配置 --
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-dependencies/artifactIdversion2.7.2/versiontypepom/typescopeimport/scope
/dependency!-- okhttp 依赖配置 --
dependencygroupIdcom.squareup.okhttp3/groupIdartifactIdokhttp/artifactIdversion4.9.3/version
/dependency简单封装获取http2client请求 /*** 获取httpClient请求** param maxTotalConnections 最大连接数* param connectionKeepAliveTimeInMillis 最长连接保持活动时间* return*/private static OkHttpClient createHttpClient(int maxTotalConnections, long connectionKeepAliveTimeInMillis) {ConnectionPool connectionPool new ConnectionPool(maxTotalConnections, connectionKeepAliveTimeInMillis, TimeUnit.MILLISECONDS);return new OkHttpClient.Builder().followRedirects(false)
// .protocols(Collections.singletonList(Protocol.H2_PRIOR_KNOWLEDGE)).retryOnConnectionFailure(true).connectionPool(connectionPool).build();}GET请求示例 /*** GET请求示例** return* throws IOException*/private String getTokenResStr() throws IOException {、Request request new Request.Builder().addHeader(Nonce, “123”).addHeader(Authorization, configData.getAuthorizationCode()).url(“url地址”).build();//GET by defaultOkHttpClient httpClient createHttpClient(100, 30000);Response response httpClient.newCall(request).execute();if (!response.isSuccessful()) {throw new IOException(Unexpected code response);}return response.body().string();}POST请求示例 /*** POST请求示例** param orderId* param tokenResStr* return* throws IOException*/private String getOrderDetail(String orderId, String tokenResStr) throws IOException {JSONObject tokenRes JSONObject.parseObject(tokenResStr);// tokenString accessToken tokenRes.getString(access_token);// token类型String tokenType tokenRes.getString(token_type);String authorizationStr firstUpperCase(tokenType) accessToken;Request request new Request.Builder().addHeader(Authorization, authorizationStr).addHeader(Content-Type, application/json).url(configData.getDetailRpcUrl() orderId).build();OkHttpClient httpClient createHttpClient(100, 30000);Response response httpClient.newCall(request).execute();if (!response.isSuccessful()) {throw new IOException(Unexpected code response);}return response.body().string();
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/921530.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!