I have coded the code below to actually perform the POST for httpURLconnection, can help me find the mistakes?
<p>The following code is my code to actually invoke a POST method over a php page called login.php that i have created before. But this code is not working and I do not know where it goes wrong. Can anybody help me? </p>

<pre><code>import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; 
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.*;


public class connectServer {
    private URL server = null;

    public connectServer(String URL) {
        try {
            server = new URL(""+URL);
        }
        catch(MalformedURLException e) {

        }
    }

    public byte[] loadHttpFilePOST(String staffid, String password) throws IOException {
        byte[] byteBuffer;
        HttpURLConnection huc = (HttpURLConnection)server.openConnection();
        try {
            huc.setRequestMethod("POST");
            huc.setDoOutput(true);
            huc.setReadTimeout(10000);
            OutputStream os = huc.getOutputStream();
            String staffID = "staffid=" + staffid;
            String passWord = "password=" + password;

            os.write(staffID.getBytes());
            os.write(passWord.getBytes());
            InputStream is = huc.getInputStream();
            try {
                int len = (int)huc.getContentLength();
                if (len &gt; 0) {
                    byteBuffer = new byte[len];
                    DataInputStream dis = new DataInputStream(is);
                    dis.readFully(byteBuffer);
                }
                else {
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    byte[] buffer = new byte[512];
                    int count;
                    while ((count = is.read(buffer)) &gt;= 0) {
                        bos.write(buffer, 0, count);
                    }
                    byteBuffer = bos.toByteArray();
                }
            }
            finally {
                is.close();
            }
        }
        finally {
            huc.disconnect();
        }   

        return byteBuffer;
    }
}
</code></pre>

<p>the following is my login.php code </p>

<pre><code>&lt;?php
    $userdb =  "root";
    $passdb =  "1234";
    $hostdb = "localhost";
    $db = "ecaldb";
    $conn = mysql_connect($hostdb,$userdb,$passdb);
    mysql_select_db($db);

    if(!$conn) {
        echo "222";
    }

    $flag = false;
    if($_POST['staffid'] !="" and $_POST['password'] != "") {
        $StaffID = $_POST['staffid'];
        $Pass = $_POST['password'];
        $flag = true;
    } 

    if($flag == true) {
        $sql = "SELECT * FROM stafftbl WHERE Staff_ID = '".$StaffID."' AND Password = '".$Pass."'";

        $result = mysql_query($sql);
        $row = mysql_fetch_assoc($result);
        if($row['Staff_ID'] == $StaffID and $row['Password'] == $Pass) {
            echo "111";
        }
        else {
            echo "222";
        }
    }
    else {
        echo "000";
    }
?&gt;
</code></pre>
