Http/2 Client API在 Java 9 中引入。它比 Http/1.1 具有更多性能改进,并且还支持服务器端推送事件。这使得网站高效且更快浏览。Http/2 Client是一个名为jdk.incubator.httpclient的孵化器模块strong>,这意味着所有功能还没有最终确定,新的变化可能会在 java 的未来版本中出现。它导出包含所有公共 API 的 jdk.incubator.http 包。
要使用 Http/2 客户端,我们需要使用 孵化器模块,我们只需使用“–add-modules”命令将httpclient 模块传递到 JShell 中,如下所示
<strong>C:\>jshell -v --add-modules jdk.incubator.httpclient | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro</strong>
示例
<strong>jshell> import jdk.incubator.http.*; jshell> HttpClient httpClient = HttpClient.newHttpClient(); httpClient ==> jdk.incubator.http.HttpClientImpl@534df152 | created variable httpClient : HttpClient jshell> HttpRequest httpRequest = HttpRequest.newBuilder().uri(new URI("https: //www.google.com")).GET().build(); httpRequest ==> https://www.google.com GET | created variable httpRequest : HttpRequest jshell> HttpResponse httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandler.asString()); httpResponse ==> jdk.incubator.http.HttpResponseImpl@609cd4d8 | created variable httpResponse : HttpResponse jshell> System.out.println(httpResponse.statusCode()); 403</strong> <strong> jshell> System.out.println(httpResponse.body()); Apache HTTP Server Test Page powered by CentOS Testing 123.. <p class="lead">This page is used to test the proper operation of the Apache HTTP server after it has been insta lled. If you can read this page it means that this site is working properly. Thi s server is powered by CentOS.</p><p class="lead">The website you just visited is either experiencing problems or is undergoing routine maintenance.</p>If you would like to let the administrators of this website know that you've seen this page instead of the page you expected, you should send them e-mail. In general, mail sent to the name "webmast er" and directed to the website's domain should reach the appropriate person.For example, if you experienced problems while visiting www.example.com, you should send e-mail to "webmaster@example .com". Are you the Administrator? <p>You should add your website content to the directory /var/www/html/.</p><p>To prevent this page from ever being used, follow the instructions in the file /etc/httpd/conf.d/welcome.conf.</p>Promoting Apache and CentOS </strong><p><strong>You are free to use the images below on Apache and CentOS Linux powered HTTP servers. Thanks for using Apache and CentOS!</strong></p>
以上是Java 9中的Http/2客户端是什么?的详细内容。更多信息请关注PHP中文网其他相关文章!

javaispopularforcross-platformdesktopapplicationsduetoits“ writeonce,runanywhere”哲学。1)itusesbytbytybytecebytecodethatrunsonanyjvm-platform.2)librarieslikeslikeslikeswingingandjavafxhelpcreatenative-lookingenative-lookinguisis.3)

在Java中编写平台特定代码的原因包括访问特定操作系统功能、与特定硬件交互和优化性能。1)使用JNA或JNI访问Windows注册表;2)通过JNI与Linux特定硬件驱动程序交互;3)通过JNI使用Metal优化macOS上的游戏性能。尽管如此,编写平台特定代码会影响代码的可移植性、增加复杂性、可能带来性能开销和安全风险。

Java将通过云原生应用、多平台部署和跨语言互操作进一步提升平台独立性。1)云原生应用将使用GraalVM和Quarkus提升启动速度。2)Java将扩展到嵌入式设备、移动设备和量子计算机。3)通过GraalVM,Java将与Python、JavaScript等语言无缝集成,增强跨语言互操作性。

Java的强类型系统通过类型安全、统一的类型转换和多态性确保了平台独立性。1)类型安全在编译时进行类型检查,避免运行时错误;2)统一的类型转换规则在所有平台上一致;3)多态性和接口机制使代码在不同平台上行为一致。

JNI会破坏Java的平台独立性。1)JNI需要特定平台的本地库,2)本地代码需在目标平台编译和链接,3)不同版本的操作系统或JVM可能需要不同的本地库版本,4)本地代码可能引入安全漏洞或导致程序崩溃。

新兴技术对Java的平台独立性既有威胁也有增强。1)云计算和容器化技术如Docker增强了Java的平台独立性,但需要优化以适应不同云环境。2)WebAssembly通过GraalVM编译Java代码,扩展了其平台独立性,但需与其他语言竞争性能。

不同JVM实现都能提供平台独立性,但表现略有不同。1.OracleHotSpot和OpenJDKJVM在平台独立性上表现相似,但OpenJDK可能需额外配置。2.IBMJ9JVM在特定操作系统上表现优化。3.GraalVM支持多语言,需额外配置。4.AzulZingJVM需特定平台调整。

平台独立性通过在多种操作系统上运行同一套代码,降低开发成本和缩短开发时间。具体表现为:1.减少开发时间,只需维护一套代码;2.降低维护成本,统一测试流程;3.快速迭代和团队协作,简化部署过程。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

SublimeText3 Linux新版
SublimeText3 Linux最新版

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能