title: Invalid request error from server in android
body: <p>I am trying to send credentials to my server but my PHP file returns:</p>
  
  <blockquote>
    <p>{"errors":["invalid_request"]}</p>
  </blockquote>
  
  <p>My code:</p>
  
  <pre><code>                JSONObject jsonObjectToSend = new JSONObject();
                  jsonObjectToSend.put("email",credentials[0].toString());
                  jsonObjectToSend.put("password",credentials[1].toString());
  
                  String message = jsonObjectToSend.toString();
  
                  HttpURLConnection conn = null;
                  URL url = new URL("http://xx.xx.xx.xx/user/login.php");
                  conn = (HttpURLConnection) url.openConnection();
                  conn.setRequestMethod("POST");
                  conn.setDoOutput(true);
                  conn.setDoInput(true);
                  conn.setFixedLengthStreamingMode(message.getBytes().length);
                  conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
                  conn.setRequestProperty("X-Requested-With", "XMLHttpRequest");
                  conn.connect();
                  OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
                  wr.write(message);
                  wr.flush();
                  BufferedReader reader = new BufferedReader (new InputStreamReader(conn.getInputStream()));
                  StringBuilder sb = new StringBuilder();
                  String line = null;
  
                  //Getting the response from the server when we try to login.
  
                  while((line = reader.readLine()) != null)
                  {
                      sb.append(line);
                      break;
                  }
                  result = sb.toString();
  </code></pre>
  
  <p>The JSON format that I need to pass is:</p>
  
  <pre><code>{
   "email": "example@gmail.com",
   "password": "123456789" 
  }
  </code></pre>
  
  <p>But I don't know which method (POST or GET) is being used in the PHP script. I have tried both methods but got the same error.</p>