Note that there are some explanatory texts on larger screens.

plurals
  1. POReceiving a JSON object from Android to a PHP Webservice
    primarykey
    data
    text
    <p>I have tried looking at several links but I cannot seem to get it right. I am trying to send a JSON object from my android application which contains 'username' and 'password'. But I am not sure if this data is actually been sent to the web-service. I am not too sure if I got the code right for reading JSON object in the php script. </p> <pre><code> JSONObject jsonObject = new JSONObject(); String userID = ""; HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(loginURI); HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 10000); HttpConnectionParams.setSoTimeout(httpParams,10000); try { jsonObject.put("username", username); jsonObject.put("password", password); JSONArray array = new JSONArray(); StringEntity stringEntity = new StringEntity(jsonObject.toString()); stringEntity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httpPost.setEntity(stringEntity); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity entity = httpResponse.getEntity(); if (entity != null) { userID = EntityUtils.toString(httpResponse.getEntity()); Log.i("Read from server", userID); } }catch (IOException e){ Log.e("Login_Issue", e.toString()); }catch (JSONException e) { e.printStackTrace(); } </code></pre> <p>Here is the beginning of the PHP script. </p> <pre><code>&lt;?php include('dbconnect.php'); $tablename = 'users'; //username and password sent from android $username=$_REQUEST['username']; $password=$_REQUEST['password']; ..... ?&gt; </code></pre> <p>Can you tell me what I'm doing wrong here please? I cannot seem to figure out. </p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload