No time for comments.
authorgumartinm <gu.martinm@gmail.com>
Thu, 24 Nov 2011 01:57:22 +0000 (02:57 +0100)
committergumartinm <gu.martinm@gmail.com>
Thu, 24 Nov 2011 01:57:22 +0000 (02:57 +0100)
Trying to establish a http connection and getting weird exception  :(

Android/Testing/Test1/src/de/android/test1/Test1Activity.java

index 117af92..d1a5768 100644 (file)
@@ -1,13 +1,22 @@
 package de.android.test1;
 
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.message.BasicNameValuePair;
-
 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
+import android.os.StrictMode;
 import android.view.View;
 import android.widget.EditText;
 
@@ -16,6 +25,12 @@ public class Test1Activity extends Activity {
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        ///JUSTE DEVELOPER MODE!!!!! GOOGLE "RECOMENDS" TO USE A DIFFERENT THREAD FOR NETWORK CONNECTIONS
+        // THE STRICTMODE WILL STOP ME USING THE NETWORK DIRECTLY IN THIS THREAD  :S (for someone coming
+        // from programming drivers this is a bit stupid... but anyway the most of the developers are idiot "word of Linus")
+        StrictMode.enableDefaults();
+        // 
+        
         setContentView(R.layout.main);
     }
     
@@ -28,7 +43,7 @@ public class Test1Activity extends Activity {
        HttpClient httpclient = new DefaultHttpClient();
        
        //RESTful WebService
-       HttpPost httppost = new HttpPost("http://10.208.184.41/userfront.php/api/51,32/0,5/gpsads.xml");
+       HttpPost httppost = new HttpPost("http://192.168.1.34/userfront.php/api/51,32/0,5/gpsads.xml");
        
        EditText uname = (EditText)findViewById(R.id.username);
         String username = uname.getText().toString();
@@ -39,14 +54,23 @@ public class Test1Activity extends Activity {
         List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
         nameValuePairs.add(new BasicNameValuePair("username", username));
         nameValuePairs.add(new BasicNameValuePair("password", password));
-        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
-
-
+        try {
+                       httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
+                       // Execute HTTP Post Request
+                       HttpResponse response = httpclient.execute(httppost);
+               } catch (UnsupportedEncodingException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (ClientProtocolException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (IOException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
 
-
-
-       Intent i = new Intent(Test1Activity.this, NextActivity.class);
-       this.startActivity(i);
+       //Intent i = new Intent(Test1Activity.this, NextActivity.class);
+       //this.startActivity(i);
     }
     
     public void onClickCancel(View v) {