Php 使用$\u POST从应用程序连接到服务器时出现问题

Php 使用$\u POST从应用程序连接到服务器时出现问题,php,android-studio,server,Php,Android Studio,Server,我是一名即将毕业的学生 我想集成应用程序和服务器 但是这个问题没有得到解决。。请帮帮我 我认为使用“$\u post”可以将数据从android发送到服务器 但这是不可能的 服务器持续派生'-1',因此android studio发生错误 请阅读我的代码,并反馈给我 **我使用php作为服务器,使用android studio <?php @extract($_POST); if(!isset($_SESSION)) { session_start(); } $con=mys

我是一名即将毕业的学生

我想集成应用程序和服务器

但是这个问题没有得到解决。。请帮帮我

我认为使用“$\u post”可以将数据从android发送到服务器

但这是不可能的

服务器持续派生'-1',因此android studio发生错误

请阅读我的代码,并反馈给我

**我使用php作为服务器,使用android studio

<?php

@extract($_POST);

if(!isset($_SESSION)) {
    session_start();
}

$con=mysqli_connect("localhost","root","1234","teamProject");

if (mysqli_connect_errno($con))
{
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

if(isset($_POST['userID']) && isset($_POST['userPW'])){

  $userID = $_POST['userID'];
  $userPW = $_POST['userPW'];

  $sql = "SELECT userPW FROM USERINFORMATION where userID='".$userID."'";

  $result = mysqli_query($con, $sql);

  $row = mysqli_fetch_array($result);

  $data = $row;

  if(strcmp($data, $userPW)){
    echo "0"; // 다르다 
  }else{
    echo "1"; // 같다 
  }
}
else{
  echo "-1"; //값이 전달되지 않았다. 
}

mysqli_close($con);
?>


如果添加
var\u dump($\u POST)会发生什么
变量转储($\u GET)password\u hash()
存储密码,并使用
password\u verify()
进行比较,您似乎在使用纯文本存储。也不需要在
$\u POST
数组上调用
extract()
,特别是当您以后显式地将数组成员提取到变量中时。我尝试使用var\u dump,但之前是相等的。。另外,服务器的结果被添加为“NULL”,我不太清楚您的意思-当您转储它时,
$\u POST
中是否存在变量?或者它们在
$\u GET
var\u dump()
的目的是查看客户机是否发送了正确的值,这样您就知道应该更详细地查看哪个端
变量转储($\u GET)password\u hash()
存储密码,并使用
password\u verify()
进行比较,您似乎在使用纯文本存储。也不需要在
$\u POST
数组上调用
extract()
,特别是当您以后显式地将数组成员提取到变量中时。我尝试使用var\u dump,但之前是相等的。。另外,服务器的结果被添加为“NULL”,我不太清楚您的意思-当您转储它时,
$\u POST
中是否存在变量?或者它们在
$\u GET
var_dump()
的目的是查看客户端是否发送了正确的值,这样您就可以更详细地了解哪一端。
HttpResponse response;
HttpClient httpClient;
private EditText user_ID, user_PW;
String userID, userPW, stan;
private String xml;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login_activity);

    /*if (Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }*/

    user_ID = (EditText) findViewById(R.id.insert_ID);
    user_PW = (EditText) findViewById(R.id.insert_PW);
}

public void login(View v) {
    userID = user_ID.getText().toString();
    ;
    userPW = user_PW.getText().toString();
    ;

    phpdo task = new phpdo();
    task.execute(userID, userPW);
    /*if(stan.equals("1")){
        Intent intent = new Intent(getApplicationContext(), MainActivity.class);
        startActivity(intent);
    }else{

    }*/

}

// 회원가입 버튼 클릭 시
public void signUp(View v) {
    Intent intent = new Intent(getApplicationContext(), SignUpActivity.class);
    startActivity(intent);
}

// 비회원 이용 버튼 클릭 시
public void nonMember(View v) {
    Intent intent = new Intent(getApplicationContext(), MainActivity.class);
    startActivity(intent);
}

// 아이디 비번 찾기 버튼 클릭 시
//  화면 구현 필요
public void findIDPW(View v) {

}

@SuppressLint("StaticFieldLeak")
private class phpdo extends AsyncTask<String, Void, String> {

    protected void onPreExecute() {

    }

    @Override
    protected String doInBackground(String... arg0) {

        try
        {
            //   전송 모드 설정 - 기본적인 설정이다
            //--------------------------

            // 전송 방식은 POST
            httpClient = new DefaultHttpClient();
            HttpPost request = new HttpPost("http://172.30.1.1/PHP_connection.php");

            Vector<NameValuePair> nameValue = new Vector<NameValuePair>();
            nameValue.add(new BasicNameValuePair("userID", userID));
            nameValue.add(new BasicNameValuePair("userPW", userPW));
            //전송하고자 하는 데이터의 신호 와 해당데이터의 값

            HttpEntity entity = new UrlEncodedFormEntity(nameValue, HTTP.UTF_8);
            request.setEntity(entity);

            HttpClient client = new DefaultHttpClient();
            HttpResponse res = client.execute(request);
            HttpEntity entityResponse = res.getEntity();
            InputStream im = entityResponse.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(im, StandardCharsets.UTF_8));

            StringBuffer sb = new StringBuffer("");
            String line = "";

            while ((line = reader.readLine()) != null) {
                sb.append(line);
                break;
            }

            im.close();

            return sb.toString();

        }catch (UnsupportedEncodingException e) {
            e.printStackTrace();

        }catch (IOException e) {
            e.printStackTrace();
        }
        return null;

    }

    protected void onPostExecute(String aVoid) {

        super.onPostExecute(aVoid);
        if (aVoid.equals("1")) {
            Intent intent = new Intent(getApplicationContext(), MainActivity.class);
            startActivity(intent);
        }
        else if(aVoid.equals("0")){
            Toast myToast = Toast.makeText(LoginActivity.this,"pass error!", Toast.LENGTH_SHORT);
            myToast.show();
        }
        else{
            Toast myToast = Toast.makeText(LoginActivity.this,"error!", Toast.LENGTH_SHORT);
            myToast.show();
        }
    }
}