Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a piece of code I wrote for registering a new username using JSON:</p> <pre><code> public static boolean register(Context myContext, String name, String pwd) { byte[] data; HttpPost httppost; StringBuffer buffer; HttpResponse response; HttpClient httpclient; InputStream inputStream; List&lt;NameValuePair&gt; nameValuePairs; try { httpclient = new DefaultHttpClient(); httppost = new HttpPost( "http://X.X.X.X/register.php"); // Add your data nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2); nameValuePairs.add(new BasicNameValuePair("User", name.trim())); nameValuePairs.add(new BasicNameValuePair("Password", pwd.trim())); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request response = httpclient.execute(httppost); inputStream = response.getEntity().getContent(); data = new byte[256]; buffer = new StringBuffer(); int len = 0; while (-1 != (len = inputStream.read(data))) { buffer.append(new String(data, 0, len)); } inputStream.close(); } catch (Exception e) { Toast.makeText(myContext, "error" + e.toString(), Toast.LENGTH_LONG) .show(); return false; } if (buffer.charAt(0) == 'Y') { return true; } else { return false; } } </code></pre> <p>If you notice:</p> <pre><code> nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2); nameValuePairs.add(new BasicNameValuePair("User", name.trim())); nameValuePairs.add(new BasicNameValuePair("Password", pwd.trim())); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); </code></pre> <p>in that piece you can send parameters.</p> <p>The method simply sends User and Password to the register.php. If the User is already taken, 'N' is returned; otherwise creates the User and returns 'Y'.</p> <p>On the server side, you treat them as POST information, so:</p> <pre><code> $user = $_POST['User']; </code></pre> <p>It should do for your case :)</p> <p>Cheers!</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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