2016-04-12 21 views
-1

Kullanıcıya iki EditText içeren bir arabirim istediğim kullanıcı adı ve parola paramları ile bir http isteği yapmaya çalışıyorum.Http urlConnection ve Asyntask ile İstek Al

Aşağıdaki hatayı şu anda alıyorum: "DoInBackground()" yürütülürken bir hata oluştu. Yardım için teşekkürler.

Bu

açıktır: Tüm

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.leonelbaidal.moodlenots"> 

    <uses-permission android:name="android.permission.INTERNET" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity 
      android:name=".MainActivity" 
      android:screenOrientation="portrait" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for 
    App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. --> 
     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 
    </application> 

</manifest> 

Ana Etkinlik:

public class MainActivity extends Activity { 

    HttpURLConnection urlConnection = null; 
    InputStream is; 
    private GoogleApiClient client; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     final EditText password; 
     final EditText username; 
     Button login; 

     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.activity_main); 

     username = (EditText) findViewById(R.id.txt_username); 
     password = (EditText) findViewById(R.id.txt_password); 
     login = (Button) findViewById(R.id.btn_loggin); 

     password.setTypeface(Typeface.DEFAULT); 
     password.setTransformationMethod(new PasswordTransformationMethod()); 

     final String httpPath = "http://10.0.23.34/android/login.php?u=" + username.getText().toString() + "&p=" + password.getText().toString(); 

     login.setOnClickListener(new View.OnClickListener() { 
      @Override 

      public void onClick(View v){ 
       new MyTask().execute(); 
      } 
     }); 

     client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); 
    } 

Ve görev sınıfı: Sonunda

private class MyTask extends AsyncTask<String, Void, Void>{ 

     String textResult; 

     @Override 
     protected Void doInBackground(String... httpPath){ 


      try { 
       URL url = new URL(httpPath[0]); 
       urlConnection = (HttpURLConnection) url.openConnection(); 
       urlConnection.setDoOutput(true); 

       BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); 
       String stringBuffer; 
       String stringText = ""; 
       while ((stringBuffer = in.readLine()) != null) { 
        stringText += stringBuffer; 
       } 

       in.close(); 
       textResult = stringText; 

      } catch (MalformedURLException e) { 
       e.printStackTrace(); 
       textResult = e.toString(); 
      } catch (IOException e){ 
       e.printStackTrace(); 
       textResult = e.toString(); 
      } 
      return null; 
     } 

     @Override 
     protected void onPostExecute(Void result){ 
      Toast.makeText(getApplicationContext(), textResult, Toast.LENGTH_SHORT).show(); 
     } 
    } 

i App uygulamaya kodlu OtomatikOluşturuldu gelmiş İndeksleme API'sı.

cevap

1

Sen url giriş param

new MyTask().execute(httpPath); 
eksik
İlgili konular