如何与HTTPS通信? (基本资料)

时间:2022-09-01 13:44:15

I'm not too familiar with networking in JAVA but what i'm basically trying to do is create a couple of threads that will "talk" to each other using HTTPS for security reasons.

我不太熟悉JAVA中的网络,但我基本上要做的是创建一些线程,出于安全原因使用HTTPS“互相交谈”。

I'm not sure about the terminology so what I'm looking for is a pointing in the right direction. Hopefully, this should be pretty easy for experienced JAVA networking programmers.

我不确定术语所以我正在寻找的是指向正确的方向。希望对于经验丰富的JAVA网络程序员来说,这应该很容易。

I've tried to research this myself but there are different methods of doing this (HttpsURLConnection? Sending a POST Request Using a URL?) and a tip from someone who's done this before could save me alot of research time.

我自己试图对此进行研究,但是有不同的方法可以做到这一点(HttpsURLConnection?使用URL发送POST请求?)以及之前完成此操作的人的提示可以节省我很多研究时间。

Thanks!

3 个解决方案

#1


HttpsURLConnection is indeed the main class, but for simple uses you can actually just do:

HttpsURLConnection确实是主类,但对于简单的用途,你实际上可以这样做:

InputStream is = new URL("https://example.com").openStream();

Consider whether you actually want to use HTTP for your application. It may make more sense to use another protocol, or raw SSL. Look at SSLSocket, SSLServerSocket, and the associated classes.

考虑您是否确实要为您的应用程序使用HTTP。使用其他协议或原始SSL可能更有意义。查看SSLSocket,SSLServerSocket和关联的类。

Java RMI (Remote Method Invocation) may also be relevant. It allows calling Java methods on remote computers, and has built-in security options. See Using RMI with SSL if you're interested in that route.

Java RMI(远程方法调用)也可能是相关的。它允许在远程计算机上调用Java方法,并具有内置的安全选项。如果您对该路由感兴趣,请参阅将RMI与SSL配合使用。

#2


If you want to stick with Http, have a look at the apache httpclient library.Its has a lot of useful http abstractions.

如果你想坚持使用Http,请看一下apache httpclient库。它有很多有用的http抽象。

#3


Check out the awesome project called Netty. It provides unified API for various transport types and already has an HTTP codec. Adding HTTPS support to your application is not so complicated with it.

看看名为Netty的很棒的项目。它为各种传输类型提供统一的API,并且已经具有HTTP编解码器。为您的应用程序添加HTTPS支持并不是那么复杂。

#1


HttpsURLConnection is indeed the main class, but for simple uses you can actually just do:

HttpsURLConnection确实是主类,但对于简单的用途,你实际上可以这样做:

InputStream is = new URL("https://example.com").openStream();

Consider whether you actually want to use HTTP for your application. It may make more sense to use another protocol, or raw SSL. Look at SSLSocket, SSLServerSocket, and the associated classes.

考虑您是否确实要为您的应用程序使用HTTP。使用其他协议或原始SSL可能更有意义。查看SSLSocket,SSLServerSocket和关联的类。

Java RMI (Remote Method Invocation) may also be relevant. It allows calling Java methods on remote computers, and has built-in security options. See Using RMI with SSL if you're interested in that route.

Java RMI(远程方法调用)也可能是相关的。它允许在远程计算机上调用Java方法,并具有内置的安全选项。如果您对该路由感兴趣,请参阅将RMI与SSL配合使用。

#2


If you want to stick with Http, have a look at the apache httpclient library.Its has a lot of useful http abstractions.

如果你想坚持使用Http,请看一下apache httpclient库。它有很多有用的http抽象。

#3


Check out the awesome project called Netty. It provides unified API for various transport types and already has an HTTP codec. Adding HTTPS support to your application is not so complicated with it.

看看名为Netty的很棒的项目。它为各种传输类型提供统一的API,并且已经具有HTTP编解码器。为您的应用程序添加HTTPS支持并不是那么复杂。