HttpUrlConnect.getInputStream()混淆

时间:2016-01-27 00:25:19

标签: java php

在我的应用程序中,我建立了这个http连接。

String first = params[1];
String last = params[2];
String email = params[3];
String password = params[4];
URL url = new URL(register_url);
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
String post_data = URLEncoder.encode("first","UTF-8")+"="+URLEncoder.encode(first,"UTF-8")+"&"
        +URLEncoder.encode("last","UTF-8")+"="+URLEncoder.encode(last,"UTF-8")+"&"+URLEncoder.encode("email","UTF-8")+"="+URLEncoder.encode(email,"UTF-8")
        +"&"+URLEncoder.encode("password","UTF-8")+"="+URLEncoder.encode(password,"UTF-8");
bufferedWriter.write(post_data);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"));
String result="";
String line="";
while((line = bufferedReader.readLine())!= null) {
    result += line;
}

上面的代码连接到远程服务器中的php文件

<?php 
require "conn.php";
$email = $_POST["email"];
$password = $_POST["password"];
$mysql_qry = "select * from arsenal_data where email like '$email' and      password like '$password';";
$result = mysqli_query($conn ,$mysql_qry);
if(mysqli_num_rows($result) > 0) {
echo " Remote login success!";
}
else {
echo " Remote login fails!";
}

?>

我的问题是为什么&#34;远程登录成功!&#34;在htttpURLConnect.getInputStream()的结果中的php文件中的echo语句中?我认为&#34; echo&#34; php文件中的语句只是显示一条消息?与php文件中的$ _GET [&#34; String&#34;]有什么区别?这两种方法都是从服务器中的php文件向客户端发送消息吗?

1 个答案:

答案 0 :(得分:0)

在PHP中,$_GET变量保存来自发送到PHP服务器的HTTP请求的查询参数。所以这是一个“输入”。 echo用于在HTTP Response正文中发回文本,因此它是“输出”。