2012-02-06 7 views
0

thisサイトにあるクラスを使用して、Webサービスを介してログインする方法を実装しようとしました。テストプログラムでログインしようとすると、ログイン試行後に出力が「応答」に設定されます。プログラムは約1秒間停止し、空文字列を出力します。私のアプリケーションがログインしようとしているかどうかを確認する方法はありますか?あるいは、インターネットにも接続していますか?以下私のアプリケーションがウェブサービスに正常にログインしていない

コードスニペット:

private RestClient restClient = new RestClient("https://service...."); 
... 
private void LoginCheck() 
{ 

    restClient.AddParam("username", username); 
    restClient.AddParam("password", userpass); 

    try { 
     restClient.Execute(RequestMethod.POST); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

    String response = restClient.getResponse(); 
    Toast.makeText(LoginActivity.this, response, Toast.LENGTH_SHORT).show(); 
} 
+2

マニフェストにインターネットアクセス許可を追加しましたか? –

+0

うん。そして私がやった後、プログラムは戻ってくる前にちょっとストールするでしょう。 – CodePrimate

答えて

0

は、私はそれが私のために働く、あなたがHTTPPost、あなたがこのような方法で行うことができますがやろうとしていると思います。

try { 
    HttpClient client = new DefaultHttpClient(); 
    String postURL = "https://service...."; 
    HttpPost post = new HttpPost(postURL); 
     List<NameValuePair> params = new ArrayList<NameValuePair>(2); 
     params.add(new BasicNameValuePair("username", "foo")); 
     params.add(new BasicNameValuePair("password", "bar")); 
     UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8); 
     post.setEntity(ent); 
     HttpResponse responsePOST = client.execute(post); 
     HttpEntity resEntity = responsePOST.getEntity(); 
     if (resEntity != null) {  
      String response = EntityUtils.toString(resEntity)); 
     } 
} catch (Exception e) { 
    e.printStackTrace(); 
} 
関連する問題