Xampp android数据抓取不工作


Xampp android data fetching not working

这是AsyncTask中的登录代码,即使用户存在

 @Override
    protected User doInBackground(Void... params) {
        ArrayList<NameValuePair> dataToSend = new ArrayList<>();
        dataToSend.add(new BasicNameValuePair("username",       user.username));
        dataToSend.add(new BasicNameValuePair("password",   user.password));
        HttpParams httpRequestParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpRequestParams,
                CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(httpRequestParams,
                CONNECTION_TIMEOUT);
        HttpClient client = new DefaultHttpClient(httpRequestParams);
        HttpPost post = new HttpPost(SERVER_ADDRESS
                + "FetchUserData.php");
        String result=null;
        User returnedUser=null;
        try {
            post.setEntity(new UrlEncodedFormEntity(dataToSend));
            HttpResponse httpResponse = client.execute(post);
            HttpEntity entity = httpResponse.getEntity();
           result = EntityUtils.toString(entity);
//returnedUser = new User(result, 42, user.username, user.password);

        } catch (Exception e) {
            e.printStackTrace();
        }

            try {
                JSONObject jObject = new JSONObject(result);
                String name = jObject.getString("name");
                int age = jObject.getInt("age");
returnedUser = new User(name, age, user.username, user.password);
            } catch (JSONException e) {
                e.printStackTrace();
            }

        return returnedUser;
    }

如果我硬编码的返回用户看到结果内容,它返回以下html代码。这是什么意思?

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
<head> 
<title>Object not found!</title> 
<link rev="made" href="mailto:postmaster@localhost" /> 
<style type="text/css"><!-- 
body { color: #000000; background-color: #FFFFFF; } 
a:link { color: #0000CC; } 
p, address {margin-left: 3em;} 
span {font-size: smaller;} 
/*]]>*/--></style> 
</head> 
<body> 
<h1>Object not found!</h1> 
<p> 

The requested URL was not found on this server. 

If you entered the URL manually please check your 
spelling and try again. 

</p> 
<p> 
If you think this is a server error, please contact 
the <a href="mailto:postmaster@localhost">webmaster</a>. 
</p> 
<h2>Error 404</h2> 
<address> 
<a href="/">192.168.1.134</a><br /> 
<span>Apache/2.4.9 (Win32) OpenSSL/1.0.1g PHP/5.5.11</span> 
</address> 
</body> 
</html>

我附加了php抓取文件

<?php
$con=mysqli_connect("localhost","root","","loginregister");
if (mysqli_connect_errno($con))
{
 echo "Failed to connect to MySQL: " , mysqli_connect_error();
}
if (isset($_POST["password"])) {$password = $_POST["password"];}else   $password = 'bimbomix';
if (isset($_POST["username"])) {$username = $_POST["username"];}else  $username = 'bimbomix';

$statement = mysqli_prepare($con, "SELECT * FROM user WHERE username = ? AND password = ?");
mysqli_stmt_bind_param($statement, "ss", $username, $password);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $user_id, $name, $age, $username, $password);
$user = array();
while(mysqli_stmt_fetch($statement)){
    $user['name'] = $name; 
    $user['age'] = $age;
    $user['username'] = $username;
    $user['password']= $password;       
}
echo json_encode($user);

mysqli_close($con);
?>

不好意思!我很抱歉。问题很简单,即使它已经让我发疯了两个星期!查看获取文件fetch_user_data。php然后查看字符串我将其命名为fetchuserdata。php你就完成了。