Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过SSL实现RESTful服务?_Ssl_Ssl Certificate_Restful Authentication_Restful Architecture - Fatal编程技术网

如何通过SSL实现RESTful服务?

如何通过SSL实现RESTful服务?,ssl,ssl-certificate,restful-authentication,restful-architecture,Ssl,Ssl Certificate,Restful Authentication,Restful Architecture,在Eclipse中运行RESTful客户端时,出现以下错误: java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(Unknown Source) at java.net.PlainSocketImpl.connectToAddr

在Eclipse中运行RESTful客户端时,出现以下错误:

java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(Unknown Source)
    at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
    at com.elkay.client.RestClient.main(RestClient.java:23)
也试着这样做。 //在标头中设置基本身份验证

 String userPassword = "password"; 
 String encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBytes()); 
 conn.setRequestProperty("Authorization", "Basic " + encoding); 
 String parameters = "username=" + URLEncoder.encode("user1", "UTF-8") + "&password=" + URLEncoder.encode("user1password", "UTF-8"); 
 printout.writeBytes (parameters);  

编辑。请查收。我没有使用球衣或CFX。就是这个简单的客户端。为什么要使用HttpUrlConnection。您应该使用HttpsUrlConnection。此外,证书是否已添加到您的受信任存储中?已尝试使用HttpsUrlConnection。此外,您能否简要介绍如何创建受信任存储,即.jks文件?因为我可以直接在浏览器中调用URL,所以它不会因为使用HTTPS而被阻止。注意:不是确切的URL,但同样。请在下一个答案中输入代码。您可以从iE的.cer的Mozilla浏览器中生成.crt。您在这两行中尝试了什么?String authString=URLEncoder.encode(“username=anushree&password=anushree”,“UTF-8”);printout.writeBytes(authString);