android中利用HttpURLConnection向服务器请求数据,代码如下:try{
                            URL url= new URL(connectURL);
                            connection= (HttpURLConnection) url.openConnection();
                            connection.setDoOutput(true);//post的情况下需要设置为true,默认是false
                            connection.setDoInput(true);//设置是否从httpURLConnection读入,默认情况是true
                            connection.setConnectTimeout(3000);
                            connection.setRequestMethod("POST"); //设置连接类型
                            connection.setRequestProperty("content-type","application/x-www-form-urlencoded");
                            //对服务器端获取或写入数据(使用输入输出流)
                            //获取连接的输出流
                            DataOutputStream outputStream=new DataOutputStream(connection.getOutputStream());
                            outputStream.writeBytes("phone="+URLEncoder.encode(phone,"UTF-8"));
                            outputStream.writeBytes("password="+URLEncoder.encode(password,"UTF-8"));
                           //不知道上面这段代码有什么问题,为什么post接不到数据?                            outputStream.flush();
                            outputStream.close(); //发送完马上关闭php代码:<?php
header("Content-type:text/html;charset=utf-8");

include('conn.php');  //可以正常连接,已经测试

// 收集从客户端传入的参数  
$phone=$_POST["phone"];            //问题是get不到phone和password
$password=$_POST["password"];
$sql="SELECT *FROM user_login where phonenum='$phone' and password='$password'";
 
    $result=$conn->query($sql);

 if($result->num_rows>0){
 echo("success");
 }
 else{
 echo("error");
 }
 
 $conn->close();
?>