title: Android App Retrieve Data from Server but in a Secure way
body: <p>Obviously I am no android or java expert. What I want to do in my Android app is, load data from a server. I already got working this part and sourcecode is attached. But I want to do it in a way which is secure. As a first step, instead of <code>http://thisismyurl.com/a.php?action=get</code> I want to do it with username/password like this: <code>http://username:password@thisismyurl.com/a.php?action=get</code> How would I do it? Should I just add the username and password part to the url? </p>
  
  <p>Lets say I've accomplished that this will not be of any of use, because someone can just open the apk and decompile the sourcecode and get the url and the username/password. so is there a truly secure way of doing that?</p>
  
  <p>I hope I am getting understood here.</p>
  
  <pre><code>String url = "http://thisismyurl.com/a.php?action=get";
  String result = Web.executeWeb(url);
  
  public class Web {
  
      public static String executeWeb(final String url) {
  
          final StringBuilder sb = new StringBuilder();
  
          Thread thread = new Thread(new Runnable() {
              public void run() 
                  {
                  try 
                  {
                      InputStream is = (InputStream) new URL(url).getContent();
                      BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                      String result, line = reader.readLine();
                      result = line;
                      while((line=reader.readLine())!=null){
                          result+=line;
                      }
  
                      sb.append(result);
                      //System.out.println(result);       
                      //Log.i("My Response :: ", result);
  
                  } catch (Exception e)
                  {
                  // TODO: handle exception
                  }
              }
            });   
  
          thread.start();
          try {
              thread.join();
          } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          return sb.toString();
  
      }   
  
  }
  </code></pre>