2011-12-09 12 views
2

Androidからhttpsを呼び出す際に問題が発生しました。 httpsサーバに接続する手順を教えてください。AndroidからHTTPSに接続 - RESTとSOAP Webサービス

httpsと正常に動作してGoogleに接続しようとしましたが、ローカルサーバーに接続しようとすると問題が発生しています。

  1. SOAPベースのWebサービスを接続したいのhttps
  2. とRESTfulなWebサービスを接続するには、httpsでJAX-WSを使用して開発しました。

  3. コードは、RESTfulな

    HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; 
    
    DefaultHttpClient client = new DefaultHttpClient(); 
    
    SchemeRegistry registry = new SchemeRegistry(); 
    SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); 
    socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); 
    registry.register(new Scheme("https", socketFactory, 443)); 
    SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry); 
    DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams()); 
    
    // Set verifier  
    HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); 
    
    // Example send http request 
    //final String url = "https://encrypted.google.com/"; 
    final String url = "https://ipaddress:8181/RESTTest/cars"; 
    HttpPost httpPost = new HttpPost(url); 
        try{ 
        HttpResponse response = httpClient.execute(httpPost); 
        System.out.println(response); 
    }catch(Exception e){ 
        e.printStackTrace(); 
    } 
    

    そのグーグルのため正常に動作しますが、私のサーバーのために働いていないと、それは

    javax.net.ssl.SSLExceptionを与えていると接続します。信頼されていないサーバ証明書

  4. SOAPとの接続コード:

    public String getString(final String methodName, Map<String, Object>  params)  throws  Exception { 
    HttpTransportSE httpsTransportSE = new   HttpTransportSE("https://ipaddress:8181/BankingWS/banking?wsdl"); 
    
    try { 
        SoapObject request = new SoapObject("https://test/", 
          methodName); 
        if(params != null && params.size() > 0){ 
         Set<String> keys = params.keySet(); 
         Iterator<String> iterator = keys.iterator(); 
         while(iterator.hasNext()){ 
          String key = iterator.next(); 
          request.addProperty(key, params.get(key)); 
          key = null; 
         } 
        } 
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
          SoapEnvelope.VER11); 
        envelope.setOutputSoapObject(request); 
    
        TrustManagerManipulator.allowAllSSL(); 
        httpsTransportSE.call(methodName, envelope); 
    
        SoapPrimitive sp = (SoapPrimitive) envelope.getResponse(); 
    
        return sp.toString(); 
    } catch (Exception exception) { 
        System.out.println(exception.toString()); 
        throw exception; 
    } 
    } 
    
    次のリンクからTrustManagerManipulatorを使用して上記のコードで3210

    http://abhinavasblog.blogspot.com/2011/07/allow-untrusted-certificate-for-https.html

これも動作していないと私は応答コードをチェックするときには、よう、

SoapFault - faultcode: 'S:Client' faultstring: 'Cannot find dispatch method for {test.WSEndPointPort}authenticate' faultactor: 'null' detail: null 

この問題を解決するために助けてください与えています私はAndroidから何らかの方法でhttpsを呼び出すことができません:(

ありがとう、あなたの時間と努力に感謝します。

は、あなたは、すべてのセキュリティチェックをバイパスするのX509TrustManagerを作成する必要があり、 イシャン

答えて

0

、ありがとうございました。あなたは、この類似した質問の例を見つけることができます:

Make a connection to a HTTPS server from Java and ignore the validity of the security certificate

または

How to ignore SSL certificate errors in Apache HttpClient 4.0

+0

こんにちはNeTeInStEiN、ご返信いただきありがとうございます。私のコードで確認してみましょう。ありがとうございます、 – Ishan

+1

問題が解決された場合は問題ありません;-) – neteinstein

+1

@NeTeInStEiNそれを無視するとセキュリティが損なわれますか? SSLを使用する主な目的は、インターネット上の通信を保護することです。それを無視することによって何か違いはありますか? – Scorpion

関連する問題