当我不使用条件时,我可以从php获取数据,但是当我使用条件时,我无法从php获取数据

时间:2015-08-02 16:35:49

标签: java php android

我的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
}

}

0 个答案:

没有答案