简体   繁体   English

在哪里可以找到有关如何在不支持https的java上设置https的示例

[英]where can i find an example of how to setup https on java where https is not supported

Does anyone have a good example of how to do https over http (or a socket)? 有没有人有一个很好的例子说明如何通过HTTP(或套接字)执行https? The embedded java platform doesn't support https out of the box, but I'm sure it should be possible using some 3rd party libraries or source code snippets. 嵌入式Java平台不支持开箱即用,但是我敢肯定,可以使用一些第三方库或源代码段来实现。

If anyone can point me to the correct direction I'd be very grateful 如果有人能指出我正确的方向,我将不胜感激

What profile are you using? 您正在使用什么个人资料? MIDP comes with HTTS handler. MIDP带有HTTS处理程序。 I just checked the code. 我刚刚检查了代码。 This package, 这个包

com.sun.midp.io.j2me.https

implements HttpsConnection interface. 实现HttpsConnection接口。

EDIT: 编辑:

I think your best bet is to find an old version of BouncyCastle JCE that works with your version of Java. 我认为您最好的选择是找到可与您的Java版本一起使用的BouncyCastle JCE的旧版本。 BC JCE comes with this class to handle SSL, BC JCE随附此类来处理SSL,

http://www.bouncycastle.org/docs/docs1.3/org/bouncycastle/crypto/tls/TlsProtocolHandler.html http://www.bouncycastle.org/docs/docs1.3/org/bouncycastle/crypto/tls/TlsProtocolHandler.html

This test shows you how to make a simple HTTPS request. 此测试向您展示如何发出简单的HTTPS请求。

http://www.java2s.com/Open-Source/Java-Document/Security/Bouncy-Castle/org/bouncycastle/crypto/tls/test/BasicTlsTest.java.htm http://www.java2s.com/Open-Source/Java-Document/Security/Bouncy-Castle/org/bouncycastle/crypto/tls/test/BasicTlsTest.java.htm

Apache HttpCore is what you need. 您需要Apache HttpCore。 See more: http://hc.apache.org/httpcomponents-core/index.html 查看更多: http : //hc.apache.org/httpcomponents-core/index.html

Br, Gabi Br,Gabi

From what i can remember, with HttpComponents you just set the socket factory to use the SSLSocketFactory and it works; 我记得,有了HttpComponents,您只需将套接字工厂设置为使用SSLSocketFactory即可; however, the SSLSocketFactory was added in Java 1.4. 但是,SSLSocketFactory是在Java 1.4中添加的。

Honestly, I would not think the Apache HttpComponents API would even work on the limited environment you described... you would most likely need an older version, from back when it was called HttpClient (I think) and part of the Jakarta Commons. 老实说,我不认为Apache HttpComponents API甚至不能在您描述的有限环境下工作...您很可能需要一个较旧的版本,从那时起它被称为HttpClient(我认为),并且是Jakarta Commons的一部分。

Good luck 祝好运

JBoss netty有一个HTTP客户端的示例 ,您只需要在HTTPRequestHandler和HTTPResponseHandler中添加SSlHandler。

As bitover has said, you can use apache http components. 正如bitbit所说,您可以使用apache http组件。 Simple example where https page need user credentials: https页面需要用户凭证的简单示例:

public static void main (String[] args){
  HttpClient httpclient = new DefaultHttpClient();
  // Note that the specified port 443 corresponds with the SSL service
  ((AbstractHttpClient) httpclient).getCredentialsProvider().setCredentials(
new AuthScope("www.moneytrackin.com", 443),
new UsernamePasswordCredentials("user", "password"));
  // Https page to access
  HttpGet httpget = new HttpGet("https://www.moneytrackin.com/api/rest/getBalance");
  HttpResponse response;

  try {
      response = httpclient.execute(httpget);

      System.out.println("State: "+response.getStatusLine().toString());
      HttpEntity entity = response.getEntity();

      if (entity != null) {
          InputStream instream = entity.getContent();
          String result= convertStreamToString(instream);
          System.out.println("Data: "+result);
          instream.close();
      }

  } catch (ClientProtocolException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }

More examples in this blog . 博客中的更多示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM