如何使用Retrofit2将数据发布到服务器后获取响应正文?
这是我的界面:
<?php
include '../db/db.php';
$username = $_POST['username'];
$password = $_POST['password'];
if(mysqli_query($conn, "INSERT INTO users VALUES(NULL, '$username', '$password', '$email', '$device_id', '$gender', '$avatar_path', '$online')")){
$loginQuery = mysqli_query($conn, "SELECT * FROM users WHERE username = '".$username."' AND device_id = '".$device_id."' LIMIT 1 ");
$row = mysqli_fetch_row($loginQuery);
$userData['user_info'] = array(array(
'id' => $row[0],
'username' => $row[1],
'password' => $row[2]
));
print(json_encode($userData));
}else{
print(json_encode(null));
}
?>
以下是我在MainActivity类中的方法:
onResponse
这是我的PHP课程
<h1>A Database Error Occurred</h1>
<p>Error Number: 2006</p><p>MySQL server has gone away</p><p>UPDATE `leads` SET `sellerId` = '41', `leadDate` = '2018-02-20'
WHERE `leadId` = '1885'</p><p>Filename: models/LeadsModel.php</p><p>Line Number: 436</p> </div>
流程:
Error while sending QUERY packet. PID=4508
(Not Works)答案 0 :(得分:0)
要发送编码数据,请尝试使用:
echo json_encode(['userData'=> $userData]);
要检索数据,您可以在模型中实现Parcelable
接口。阅读更多here。
希望它有所帮助。