2016-04-07 4 views
0

androidアプリケーションからAPIを呼び出す際に問題が発生しました。 Apiは私がブラウザからそれらを呼び出すとき問題を作成しません。私は以下のコードを投稿しています。私が得たエラーを取得します。javax.net.ssl.SSLException

HttpResponse httpresponse=null; 

    try { 
     HttpClient client = new DefaultHttpClient(); 
     HttpClient httpclient2 = new DefaultHttpClient(); 
     HttpEntity entity=null;         
     HttpPost post=new HttpPost(url); 
     post.setEntity(new UrlEncodedFormEntity(parList,"UTF-8")); 
     httpresponse= client.execute(post); 
     entity=httpresponse.getEntity(); 
     response=EntityUtils.toString(entity); 

     Log.d("code of response", ""+httpresponse.getStatusLine().getStatusCode()); 

     if(httpresponse.getStatusLine().getStatusCode()==200){ 
      if (httpresponse.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { 


       Log.d("code", ""+httpresponse.getStatusLine().getStatusCode()); 

       Header authHeader = httpresponse.getFirstHeader(AUTH.WWW_AUTH); 
       DigestScheme digestScheme = new DigestScheme(); 

       //Parse realm, nonce sent by server. 
       digestScheme.processChallenge(authHeader); 

       UsernamePasswordCredentials creds = new UsernamePasswordCredentials("cuztomise", "123456"); 
       post.addHeader(digestScheme.authenticate(creds, post)); 

       ResponseHandler<String> responseHandler = new BasicResponseHandler(); 
       String responseBody = httpclient2.execute(post, responseHandler); 
       return responseBody; 
      } 
      return response; 
      }else{ 

       makelogs(url, "", parList.toString(),""+httpresponse.getStatusLine().getStatusCode(),context_new,response); 
       return response; 
      } 
    } catch (IOException | MalformedChallengeException | AuthenticationException e) { 
     // TODO Auto-generated catch block 

     makelogs(url, e.toString(), parList.toString(),""+httpresponse.getStatusLine().getStatusCode(),context_new,response); 
     e.printStackTrace(); 
     return e.toString(); 
    }catch (Exception e) { 
     // TODO: handle exception 
     makelogs(url, e.toString(), parList.toString(),""+httpresponse.getStatusLine().getStatusCode(),context_new,response); 
     e.printStackTrace(); 
     return e.toString(); 
    } 

エラーがjavax.net.ssl.SSLException

+0

これはあなたに役立つかもしれませんhttp://stackoverflow.com/questions/2642777/trusting-all-certificates-using-httpclient-over-https – mubeen

答えて

0

これは、クライアント・マシンで確立された接続 によるものであるが、安全ではない です。

これは、HTTPSサーバーではなくHTTPサーバーと通信していることが原因です。 HTTPSに正しいポート番号を使用しなかった可能性があります。

関連する問題