对于注册表单,我使用Uri.builder在httpurlconnection中发送用户名,密码和电子邮件ID,但是在PHP端接收值时出现问题。我验证了它发送200的响应代码。
爪哇:
@Override
protected Void doInBackground(Void... params) {
try {
URL url = new URL(SERVER_ADDRESS + "Register.php");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setReadTimeout(CONNECTION_TIMEOUT);
Uri.Builder builder = new Uri.Builder()
.appendQueryParameter("username", user.username)
.appendQueryParameter("password", user.password)
.appendQueryParameter("email", user.email);
String query = builder.build().getEncodedQuery();
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(query);
writer.flush();
writer.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
PHP:
<?php
$con=mysqli_connect("localhost","xxx","xxx","xxxx");
$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];
$sql = "INSERT INTO my_table(username, password, email) VALUES ('$username', '$password', '$email')";
mysqli_query($con,$sql);
echo $email;
mysqli_close($con);
?>
这些值是作为用户名&amp;密码和电子邮件传递的,我是否需要进行一些操作才能重新获取值?