2011-12-11 8 views
0

私はアンドロイドでアプリケーションを開発しています。インターネットにアクセスできないようにします。
私は目的に役立つjavaにHttpメソッドがあることを思い出しましたが、私はそれらを検索しましたが結果はありませんでした。私は、プロキシ "IP:ポート"を持つサーバーを持っている間に、アンドロイドアプリケーションでインターネットに接続する方法を学び、ユーザー名とパスワードを要求します。

だから、私はどのように私のログインユーザ名とパスワードとドメイン名で、サーバのIPアドレスとポート番号を入れているのですか?

注:私はエミュレータをAPNに行くことでインターネットに接続するように設定しており、ブラウザを介してインターネットに正常に接続します。

答えて

0

は、次のコード

働い
/** 
* A simple example that uses HttpClient to execute an HTTP request 
* over a secure connection tunneled through an authenticating proxy. 
*/ 
public class ClientProxyAuthentication { 

    public static void main(String[] args) throws Exception { 

     DefaultHttpClient httpclient = new DefaultHttpClient(); 
     try { 
      httpclient.getCredentialsProvider().setCredentials(
        new AuthScope("localhost", 8080), 
        new UsernamePasswordCredentials("username", "password")); 

      HttpHost targetHost = new HttpHost("www.verisign.com", 443, "https"); 
      HttpHost proxy = new HttpHost("localhost", 8080); 

      httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); 

      HttpGet httpget = new HttpGet("/"); 

      System.out.println("executing request: " + httpget.getRequestLine()); 
      System.out.println("via proxy: " + proxy); 
      System.out.println("to target: " + targetHost); 

      HttpResponse response = httpclient.execute(targetHost, httpget); 
      HttpEntity entity = response.getEntity(); 

      System.out.println("----------------------------------------"); 
      System.out.println(response.getStatusLine()); 
      if (entity != null) { 
       System.out.println("Response content length: " + entity.getContentLength()); 
      } 
      EntityUtils.consume(entity); 

     } finally { 
      // When HttpClient instance is no longer needed, 
      // shut down the connection manager to ensure 
      // immediate deallocation of all system resources 
      httpclient.getConnectionManager().shutdown(); 
     } 
    } 
} 
+0

を使用してみてください!ありがとうございました :)!ありがとうございました :)!ありがとうございました :)!!!あなたは私にlottttt感謝を手伝った! – arhmn

関連する問題