2017-02-07 5 views
0

私はJSON文字列ジャワするSystem.setPropertyプロキシ

 HttpURLConnection inputStream = (HttpURLConnection) myURL.openConnection(); 


     inputStream.setRequestProperty("Authorization", "Basic " + authStringEncoded); 

を取得するためにHTTP URLにauthentificateするためにこれを使用しています私は、プロキシ経由で私の接続を構築するために

System.setProperty("https.proxyHost", host); 
     System.setProperty("https.proxyPort", port); 

を使用する必要があります。今私の新しいプロキシは認証も必要です。追加するだけでいいですか?

System.setRequestProperty("Authorization", "Basic " + authStringEncoded); 

答えて

1

httpsターゲットで試しているので、以下のコードが必要です。 Authenticatorをチェックすると、下に提供されている最小限のものよりも網羅的です。

Authenticator.setDefault(new Authenticator() { 
     @Override 
     protected PasswordAuthentication getPasswordAuthentication() { 
      return new PasswordAuthentication("user", "pwd".toCharArray()); 
     } 
    }); 

あなたはhttpリンクを扱っている場合は、自分自身以下の要求にProxy-Authorizationヘッダを追加することで十分であろう -

inputStream.setRequestProperty("Proxy-Authorization", "Basic " + authStringEncoded);