android studio 2.2.3无法使用模拟器转换来宾DNS ip:模拟器窗口不在视图中并被重新登录

时间:2017-04-26 16:28:04

标签: java android dns

如何解决此类错误消息。

package com.edupointbd.amirul.webapplogin;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

/**
 * Created by amirul on 26-Apr-17.
*/

public class BackgroundTask extends AsyncTask<String, Void, String> {

Context ctx;

BackgroundTask(Context ctx){
    this.ctx = ctx;
}


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

    String reg_url = "http://10.0.2.2/webapp/register.php";
    String logun_url = "http://10.0.2.2/webapp/login.php";

    String method = params[0];

    if ((method.equals("register"))){

        String name = params[1];
        String user_name = params[2];
        String user_pass = params[3];

        try {
            URL url = new URL(reg_url);

            HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
            httpURLConnection.setRequestMethod("POST");
          //  httpURLConnection.setDoOutput(true);

            OutputStream OS = httpURLConnection.getOutputStream();
            BufferedWriter bufferedWriter  = new BufferedWriter(new OutputStreamWriter(OS,"UTF-8"));

            String data = URLEncoder.encode("user","UTF-8") +"="+URLEncoder.encode(name,"UTF-8")+"&"+
                            URLEncoder.encode("user_name","UTF-8") +"="+URLEncoder.encode(user_name,"UTF-8")+"&"+
                    URLEncoder.encode("user_pass","UTF-8") +"="+URLEncoder.encode(user_pass,"UTF-8");



            bufferedWriter.write(data);
            bufferedWriter.flush();
            bufferedWriter.close();
            OS.close();

            InputStream IS = httpURLConnection.getInputStream();
            IS.close();
            return "Registration successful........";

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
   return null;
}

@Override
protected void onPreExecute() {
    super.onPreExecute();
}



@Override
protected void onProgressUpdate(Void... values) {
    super.onProgressUpdate(values);
}

@Override
protected void onPostExecute(String result) {
    Toast.makeText(ctx,result,Toast.LENGTH_LONG).show();
}

}

php代码 的 register.php

    <?php
require "init.php";
$name= $POST["user"];
$user_name = $POST["user_name"];
$user_pass = $POST["user_pass"];

$sql = "insert into user_info values('$name','$user_name','$user_pass');";

if(mysqli_query($con,$sql)){
    //echo"insert successufully";
}else{
    //echo"insert error".mysqli_errno($con);
}

?>

当我点击注册按钮时,数据库插入空行。变量名与数据库列名相同。我无法理解哪里出错了。 提前谢谢。

0 个答案:

没有答案