title: Target Host Error, while post a HTTP-Request
body: <p><strong>What I try to do</strong></p>
  
  <hr>
  
  <p>I'm trying to create a Loginmask for my App. To check if a userslogin is correct I create a HTTP-Post(JSON) to my server, from there I get response if the user is in the db-table or not.</p>
  
  <p>For the moment the HTTP-POST dosn't work, I allways get this Error:</p>
  
  <pre><code>12-26 14:02:22.871: W/System.err(869): java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=api.i-v-o.ch
  </code></pre>
  
  <p>This seems really strange in my eyes because i defined the URL-Path.</p>
  
  <p><strong>Question</strong></p>
  
  <hr>
  
  <p>Like you saw, the problem is that i can't etablish a Network Connection. Please tell me where the error is in my code, that I can fix it.</p>
  
  <p>It would be also really great, if you could provide me a good tutorial for this, or a codesample, that I can fix the error on my own.</p>
  
  <p>Thx for your help in Advance.</p>
  
  <p>Down here you find the Code of my Activity and my DataHandler.</p>
  
  <p>LoginActivity.class:</p>
  
  <pre><code>package de.ivocore;
  
  import de.ivocore.service.DataHandler;
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  
  public class LoginActivity extends Activity {
  
      public DataHandler JSONLogin = new DataHandler();
  
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.login);
  
          //Text-Felder 
          final EditText user = (EditText) findViewById(R.id.edt_username);
          final EditText pwd = (EditText) findViewById(R.id.edt_password);
  
          //Button
          Button loginbt = (Button) findViewById(R.id.bt_login);
  
  
  
          //OnClickListner für den Button definieren
          loginbt.setOnClickListener(new View.OnClickListener(){
  
              public void onClick(View v){
  
                  //Strings definieren
                  final String usertxt = user.getText().toString();
                  final String pwdtxt = pwd.getText().toString();
  
                  if (usertxt != null &amp;&amp; pwdtxt != null){
                  JSONLogin.JSONLogin(usertxt, pwdtxt);
                  }else{
                      Toast.makeText(LoginActivity.this, "Bitte Username und Passwort eingeben!", Toast.LENGTH_SHORT);
                  }
              }
          });
      }
  }
  </code></pre>
  
  <hr>
  
  <p>DataHandler.class</p>
  
  <pre><code>package de.ivocore.service;
  
  import java.io.BufferedReader;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  
  import org.apache.http.HttpResponse;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.entity.StringEntity;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.message.BasicHeader;
  import org.apache.http.params.HttpConnectionParams;
  import org.apache.http.protocol.HTTP;
  import org.json.JSONObject;
  
  import android.os.Looper;
  import android.util.Log;
  
  public class DataHandler {
  
      /** LOGIN-Methode
       * Für diese Methode muss ein "final String username" sowie ein "final String password" mitgegeben werden
       * Die Methode fürt die Login-Prozedur mit dem api.i-v-o.ch durch.
       * Zurückgeben wird die Response welche vom Server kommt (Login erfolgreich oder nicht), sowie der Sessionkey.
       *  */
      public void JSONLogin(final String username, final String password){
  
  
          Thread t = new Thread(){                                                            //Neuen Thread definieren
  
  
              public void run(){                                                                  //Startet automatisch wenn der Thread gestartet wird, führt die Funktion aus
  
  
                  String URL = "api.i-v-o.ch";                                                            //URL definieren für JSON-Post
                  Looper.prepare();                                                                       //Erstellt den Nachrichten-Pool
                  HttpClient client = new DefaultHttpClient();                                            //HttpClient definieren, handelt den http datenverkehr
                  HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);                   //Timeout Limite
                  HttpResponse response;                                                                  //HttpResponse definieren, handelt den http response
                  JSONObject login = new JSONObject();                                                    //JSON-Object welches gesendet wird
  
                  try{
                      HttpPost post = new HttpPost(URL);                                                  //HttpPost definieren, handelt den http post
                      login.put("username", username);                                                    //Füget dem JSONObject Login den Username ein
                      login.put("password", password);                                                    //Fügt dem JSONObject Login das Passwort ein
  
                      StringEntity se = new StringEntity("Login" + login.toString());                     //StringEntity definieren und StringEntity aus dem JSONObject Login erstellen
                      se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
                      post.setEntity(se);                                                                 //Hier wird der Post an das IVO-Core gesendet
                      response = client.execute(post);                                                    //Hier wird die Response abgefangen
  
  
                      /** Response-Checker
                       * Hier wird gecheckt was wir in der Response bekommen
                       */
                      if(response != null){                                                               //Hier wird geprüft ob etwas in der Response ist
  
                          StringBuilder sb = new StringBuilder();                                         //Stringbuilder um aus dem Response einen String zu erstellen
                          BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));   //response vom inputstreamreader lesen und in einen bufferedreader einfügen um diesen anschliessend zu einem string hinzuzuzfügen und in ein json object umwandeln
  
                          String line;                                                                    //String definieren darin ist die später die response
                          while ((line = rd.readLine()) != null) {                                        //Hier wird definiert das der String Line den inhalt vom bufferedreader ist, der duchgand wird mit readLine durchgeführt
                              sb.append(line + "\n");                                                     //Hier wird der string line nach \n gesplittet (newline)
                              }
  
                          String result;                                                                  //String result definieren
                          result = sb.toString();                                                         //Hier wird der inhalt vom Stringbuilder zum String result hinzugefühgt
                          Log.d("DataHandler", "Append String " + result);                                //Gibt aus was im result drin ist
  
  
                      }
  
                  } catch(Exception e){
                      e.printStackTrace();
                      Log.e("DataHandler", "Cannot Estabilish Connection");
                  }
                  Looper.loop();                                                                          //Nachrichten loopen
              }
          };
          t.start();                                                                                      //Thread starten
      }
  
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Logcat:</strong></p>
  
  <pre><code>12-26 14:00:29.331: W/System.err(869): java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=api.i-v-o.ch
  12-26 14:00:29.331: W/System.err(869):  at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:591)
  12-26 14:00:29.331: W/System.err(869):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:293)
  12-26 14:00:29.331: W/System.err(869):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
  12-26 14:00:29.331: W/System.err(869):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
  12-26 14:00:29.331: W/System.err(869):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
  12-26 14:00:29.341: W/System.err(869):  at de.ivocore.service.DataHandler$1.run(DataHandler.java:51)
  12-26 14:00:29.341: E/DataHandler(869): Cannot Estabilish Connection
  12-26 14:02:22.871: W/System.err(869): java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=api.i-v-o.ch
  12-26 15:09:44.431: W/System.err(936): java.net.UnknownHostException: Unable to resolve host "api.i-v-o.ch": No address associated with hostname
  12-26 15:09:44.441: W/System.err(936):  at java.net.InetAddress.lookupHostByName(InetAddress.java:426)
  12-26 15:09:44.441: W/System.err(936):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
  12-26 15:09:44.441: W/System.err(936):  at java.net.InetAddress.getAllByName(InetAddress.java:220)
  12-26 15:09:44.441: W/System.err(936):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
  12-26 15:09:44.441: W/System.err(936):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
  12-26 15:09:44.451: W/System.err(936):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
  12-26 15:09:44.451: W/System.err(936):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
  12-26 15:09:44.451: W/System.err(936):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
  12-26 15:09:44.481: W/System.err(936):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
  12-26 15:09:44.501: W/System.err(936):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
  12-26 15:09:44.501: W/System.err(936):  at de.ivocore.service.DataHandler$1.run(DataHandler.java:51)
  12-26 15:09:44.501: W/System.err(936): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
  12-26 15:09:44.511: W/System.err(936):  at libcore.io.Posix.getaddrinfo(Native Method)
  12-26 15:09:44.511: W/System.err(936):  at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
  12-26 15:09:44.511: W/System.err(936):  at java.net.InetAddress.lookupHostByName(InetAddress.java:411)
  12-26 15:09:44.511: W/System.err(936):  ... 10 more
  12-26 15:09:44.511: E/DataHandler(936): Cannot Estabilish Connection
  </code></pre>