我的php
代码是正确的。但是当我在代码中使用条件时,我遇到了一个奇怪的问题。我的php
代码发送了" A"从服务器到android的字符串。在以下代码中,当我在GetText()
方法的代码中不使用条件时,我可以获取A
字符串并将其显示在TextView
井中。但是当我使用如下条件时,我无法在TextView
中获取并显示A字符串。请帮我。我不知道这个问题在哪里。
Pass = pass.getText().toString();
// Create data variable for sent values to server
String data = URLEncoder.encode("name", "UTF-8") + "=" + URLEncoder.encode(Name, "UTF-8");
data += "&" + URLEncoder.encode("email", "UTF-8") + "=" + URLEncoder.encode(Email, "UTF-8");
data += "&" + URLEncoder.encode("user", "UTF-8") + "=" + URLEncoder.encode(Login, "UTF-8");
data += "&" + URLEncoder.encode("pass", "UTF-8") + "=" + URLEncoder.encode(Pass, "UTF-8");
String text = "";
BufferedReader reader = null;
// Send data
try{
// Defined URL where to send data
URL url = new URL("http://127.0.0.1:8080/apps/reg.php");
// Send POST data request
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the server response
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
// Read Server Response
while((line = reader.readLine()) != null){
// Append server response in string
sb.append(line);
}
text = sb.toString();
} catch(Exception ex){
} finally{
try{
reader.close();
} catch(Exception ex){}
}
// Show response on activity
String A = "A";
if(text.equals(A)){
content.setText(text); //it can not display the text in the TextView
}
}