title: JSON request in android not working
body: <p>I created a web service in asp.net which is to receive the following url:</p>
  
  <pre><code>http://localhost:31804/api/defaultapi/login?empNum=123456&amp;surname=Yusuf 
  </code></pre>
  
  <p>and send the following json
          {"$id":"1","EmployeeID":2,"Firstname":"Abayomi","Surname":"Yusuf","DepartmentID":1,"EmployeeNumber":"123456"}</p>
  
  <p>This works on my browser.</p>
  
  <p>Now I am trying to consume that web service in my android app. 
  I'm a total beginner and i am using the JSON parser class created by Andrew Barber here <a href="https://stackoverflow.com/questions/9605913/how-to-parse-json-in-android">How to parse JSON in Android</a> (last comment)</p>
  
  <pre><code>public class JSONParser {
  static InputStream is = null;
  static JSONObject jObj = null;
  static String json = "";
  
  // constructor
  public JSONParser() {
  
  }
  
  public JSONObject getJSONFromUrl(String url) {
  
  // Making HTTP request
  try {
      // defaultHttpClient
      DefaultHttpClient httpClient = new DefaultHttpClient();
      HttpPost httpPost = new HttpPost(url);
  
      HttpResponse httpResponse = httpClient.execute(httpPost);
      HttpEntity httpEntity = httpResponse.getEntity();
      is = httpEntity.getContent();
  
  } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
  } catch (ClientProtocolException e) {
      e.printStackTrace();
  } catch (IOException e) {
      e.printStackTrace();
  }
  
  try {
      BufferedReader reader = new BufferedReader(new InputStreamReader(
              is, "iso-8859-1"), 8);
      StringBuilder sb = new StringBuilder();
      String line = null;
      while ((line = reader.readLine()) != null) {
          sb.append(line + "\n");
      }
      is.close();
      json = sb.toString();
  } catch (Exception e) {
      Log.e("Buffer Error", "Error converting result " + e.toString());
  }
  
  // try parse the string to a JSON object
  try {
      jObj = new JSONObject(json);
  } catch (JSONException e) {
      Log.e("JSON Parser", "Error parsing data " + e.toString());
  }
  
  // return JSON String
  return jObj;
  
  }
  }
  </code></pre>
  
  <p>this is how i used it in my code. A button has loadHome method as its onClick event</p>
  
  <pre><code>public class Main extends Activity {
  
  private SharedPreferences employeeDetails;
  
  private static final String EMP_ID = "EmployeeID";
  private static final String EMP_NAME = "Firstname";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.login);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  public void loadHome(View view)
  {
      EditText empNumEditText = (EditText)findViewById(R.id.employeeNumEditText);
      EditText surnameEditText = (EditText)findViewById(R.id.surnameEditText);
      TextView empNumError = (TextView)findViewById(R.id.empNumWarningTextView);
      TextView surnameError = (TextView)findViewById(R.id.surnameWarningTextView);
      TextView displayError = (TextView)findViewById(R.id.errorTextView);
  
      String employeeNumber = empNumEditText.getText().toString();
      String surname = surnameEditText.getText().toString();
  
      //ensure that the form was completed
      if((employeeNumber.length()&gt;0) &amp;&amp; (surname.length()&gt;0))
      {
          try{
              String encodedEmployeeNumber = URLEncoder.encode(employeeNumber, "UTF-8");
              String encodedSurname = URLEncoder.encode(surname, "UTF-8");
  
              String loginURL = "localhost:31804/api/defaultapi/login?empNum=" + encodedEmployeeNumber + "&amp;surname=" + encodedSurname;
  
  
              // Creating JSON Parser instance
              JSONParser jParser = new JSONParser();
  
              // getting JSON string from URL
              JSONObject json = jParser.getJSONFromUrl(loginURL);
              String empId = json.getString(EMP_ID);
              String empSur = json.getString(EMP_NAME);
  
              displayError.setText(empSur);
              }
          catch(Exception e){
              displayError.setText("Whoops - something went wrong!");
              e.printStackTrace();
          }
  
      } 
      else //display error messages
      {
          if (employeeNumber.length()&gt;0){
              empNumError.setText(" ");
          }else{
              empNumError.setText("Enter Your Employee Number");
          }
  
          if (surname.length()&gt;0){
              surnameError.setText(" ");
          }else{
              surnameError.setText("Enter Your Surname");
          }
      }
  
  }
  </code></pre>
  
  <p>I keep getting the error ("Whoops - something went wrong!") in the displayError textView. What am i doing wrong.</p>
  
  <p>Here is a link to the stack trace
  <a href="http://3.bp.blogspot.com/-jJnZ71KC5ZM/UUjVQhbzKCI/AAAAAAAAAMk/v9j_bhIkOEg/s1600/1.jpg" rel="nofollow noreferrer">http://3.bp.blogspot.com/-jJnZ71KC5ZM/UUjVQhbzKCI/AAAAAAAAAMk/v9j_bhIkOEg/s1600/1.jpg</a></p>