将数据从java发送到php文件

将数据从java发送到php文件,java,php,android,Java,Php,Android,我想通过php文件将这些数据发布到数据库中。现在,用户名、公司、股份和日期都被发布在数据库中。我想发布“Edward”、“AHCL”、“10”和“23-04-2015” 你应该考虑向你的PHP页面发送GET或POST请求。 在此处查看如何发送POST请求: 然后,您的PHP脚本可以使用以下命令获取变量的值: $_POST['Username'] 你应该考虑向你的PHP页面发送GET或POST请求。 在此处查看如何发送POST请求: 然后,您的PHP脚本可以使用以下命令获取变量的值: $_POS

我想通过php文件将这些数据发布到数据库中。现在,用户名、公司、股份和日期都被发布在数据库中。我想发布“Edward”、“AHCL”、“10”和“23-04-2015”


<>你应该考虑向你的PHP页面发送GET或POST请求。 在此处查看如何发送POST请求:

然后,您的PHP脚本可以使用以下命令获取变量的值:

$_POST['Username']

<>你应该考虑向你的PHP页面发送GET或POST请求。 在此处查看如何发送POST请求:

然后,您的PHP脚本可以使用以下命令获取变量的值:

$_POST['Username']

<>你应该考虑向你的PHP页面发送GET或POST请求。 在此处查看如何发送POST请求:

然后,您的PHP脚本可以使用以下命令获取变量的值:

$_POST['Username']

<>你应该考虑向你的PHP页面发送GET或POST请求。 在此处查看如何发送POST请求:

然后,您的PHP脚本可以使用以下命令获取变量的值:

$_POST['Username']
尝试改变

 ps.print("&Username=Username");
    ps.print("&Company=Company");               
    ps.print("&Shares=Shares");
    ps.print("&Date=Date");

尝试改变

 ps.print("&Username=Username");
    ps.print("&Company=Company");               
    ps.print("&Shares=Shares");
    ps.print("&Date=Date");

尝试改变

 ps.print("&Username=Username");
    ps.print("&Company=Company");               
    ps.print("&Shares=Shares");
    ps.print("&Date=Date");

尝试改变

 ps.print("&Username=Username");
    ps.print("&Company=Company");               
    ps.print("&Shares=Shares");
    ps.print("&Date=Date");


在代码的基础上完成ie从JAVA向PHP传递(post)数据,在这两种情况下获取和显示。 JAVA端

      String UserName="Edward";
      String Company = "AHCL";
      String Shares= "10";
      String Date= "23-04-2015";

  try {
        // open a connection to the site
        URL url = new URL("http://10.0.2.2:8080//test/example.php");
        URLConnection con = url.openConnection();
        // activate the output
        con.setDoOutput(true);
        PrintStream ps = new PrintStream(con.getOutputStream());
        // send your parameters to your site
        ps.print("&Username=" + Username);
        ps.print("&Company=" + Company);               
        ps.print("&Shares=" + Shares);
        ps.print("&Date=" + Date);


        // we have to get the input stream in order to actually send the request
        con.getInputStream();
        // print out to confirm
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String line = null;
        while ((line = in.readLine()) != null) {
        System.out.println(line);
        // close the print stream
        ps.close();
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
        } catch (IOException e2) {
            e2.printStackTrace();
        }







     // creating new product in background thread
     //new CreatePortfolio().execute();
PHP


在代码的基础上构建,使其能够完成从JAVA到PHP的ie传递(post)数据,在这两种情况下获取和显示数据。 JAVA端

      String UserName="Edward";
      String Company = "AHCL";
      String Shares= "10";
      String Date= "23-04-2015";

  try {
        // open a connection to the site
        URL url = new URL("http://10.0.2.2:8080//test/example.php");
        URLConnection con = url.openConnection();
        // activate the output
        con.setDoOutput(true);
        PrintStream ps = new PrintStream(con.getOutputStream());
        // send your parameters to your site
        ps.print("&Username=" + Username);
        ps.print("&Company=" + Company);               
        ps.print("&Shares=" + Shares);
        ps.print("&Date=" + Date);


        // we have to get the input stream in order to actually send the request
        con.getInputStream();
        // print out to confirm
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String line = null;
        while ((line = in.readLine()) != null) {
        System.out.println(line);
        // close the print stream
        ps.close();
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
        } catch (IOException e2) {
            e2.printStackTrace();
        }







     // creating new product in background thread
     //new CreatePortfolio().execute();
PHP


在代码的基础上构建,使其能够完成从JAVA到PHP的ie传递(post)数据,在这两种情况下获取和显示数据。 JAVA端

      String UserName="Edward";
      String Company = "AHCL";
      String Shares= "10";
      String Date= "23-04-2015";

  try {
        // open a connection to the site
        URL url = new URL("http://10.0.2.2:8080//test/example.php");
        URLConnection con = url.openConnection();
        // activate the output
        con.setDoOutput(true);
        PrintStream ps = new PrintStream(con.getOutputStream());
        // send your parameters to your site
        ps.print("&Username=" + Username);
        ps.print("&Company=" + Company);               
        ps.print("&Shares=" + Shares);
        ps.print("&Date=" + Date);


        // we have to get the input stream in order to actually send the request
        con.getInputStream();
        // print out to confirm
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String line = null;
        while ((line = in.readLine()) != null) {
        System.out.println(line);
        // close the print stream
        ps.close();
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
        } catch (IOException e2) {
            e2.printStackTrace();
        }







     // creating new product in background thread
     //new CreatePortfolio().execute();
PHP


在代码的基础上构建,使其能够完成从JAVA到PHP的ie传递(post)数据,在这两种情况下获取和显示数据。 JAVA端

      String UserName="Edward";
      String Company = "AHCL";
      String Shares= "10";
      String Date= "23-04-2015";

  try {
        // open a connection to the site
        URL url = new URL("http://10.0.2.2:8080//test/example.php");
        URLConnection con = url.openConnection();
        // activate the output
        con.setDoOutput(true);
        PrintStream ps = new PrintStream(con.getOutputStream());
        // send your parameters to your site
        ps.print("&Username=" + Username);
        ps.print("&Company=" + Company);               
        ps.print("&Shares=" + Shares);
        ps.print("&Date=" + Date);


        // we have to get the input stream in order to actually send the request
        con.getInputStream();
        // print out to confirm
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String line = null;
        while ((line = in.readLine()) != null) {
        System.out.println(line);
        // close the print stream
        ps.close();
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
        } catch (IOException e2) {
            e2.printStackTrace();
        }







     // creating new product in background thread
     //new CreatePortfolio().execute();
PHP




我尝试使用该方法,但通过该方法我得到了很多错误,因此我切换到该方法。难道没有任何方法可以使用此方法发送变量数据吗?您的问题过于复杂了。尝试在中运行JavaHTTPPOST请求代码,我尝试使用该方法,但是通过该方法我得到了很多错误,所以我切换到该方法。难道没有任何方法可以使用此方法发送变量数据吗?您的问题过于复杂了。尝试在中运行JavaHTTPPOST请求代码,我尝试使用该方法,但是通过该方法我得到了很多错误,所以我切换到该方法。难道没有任何方法可以使用此方法发送变量数据吗?您的问题过于复杂了。尝试在中运行JavaHTTPPOST请求代码,我尝试使用该方法,但是通过该方法我得到了很多错误,所以我切换到该方法。难道没有任何方法可以使用此方法发送变量数据吗?您的问题过于复杂了。试着运行JavaHTTPPOST请求代码没有问题,我总是看到其他人在这里处理复杂的事情,我主要做PHP工作,所以我选择最简单的方式,而不是最难的编码方式。很高兴你成功了我还有一个问题。在我的php文件中,我正在运行这个查询$结果=mysql_查询(“选择公司、股票、来自组合的日期,其中Username='edward')或死亡(mysql_error());现在,我想传递一个变量,并在用户名为该变量值时检索行。您应该使用mysqli而不是mysql,它是最新的表单。但这可能会帮助你开始$USER_NAME=$_请求['username']$Q=mysqli_query($conn,“从
portfolio
WHERE
Username
=“$USER_NAME”中选择*);如果(mysqli_num_rows($Q)>0){//echo“用户名已经存在”}否则{do code}这个框很难显示所有正确的编码,所以如果你看不懂,就发布一个新问题的链接,我可以把它放在那里。没问题,我总是看到其他人在这里讨论复杂的事情,我主要做PHP工作,所以我选择最简单的方法,而不是最难的最编码的方法。很高兴你成功了我还有一个问题。在我的php文件中,我正在运行这个查询$结果=mysql_查询(“选择公司、股票、来自组合的日期,其中Username='edward')或死亡(mysql_error());现在,我想传递一个变量,并在用户名为该变量值时检索行。您应该使用mysqli而不是mysql,它是最新的表单。但这可能会帮助你开始$USER_NAME=$_请求['username']$Q=mysqli_query($conn,“从
portfolio
WHERE
Username
=“$USER_NAME”中选择*);如果(mysqli_num_rows($Q)>0){//echo“用户名已经存在”}否则{do code}这个框很难显示所有正确的编码,所以如果你看不懂,就发布一个新问题的链接,我可以把它放在那里。没问题,我总是看到其他人在这里讨论复杂的事情,我主要做PHP工作,所以我选择最简单的方法,而不是最难的最编码的方法。很高兴你成功了我还有一个问题。在我的php文件中,我正在运行这个查询$结果=mysql_查询(“选择公司、股票、来自组合的日期,其中Username='edward')或死亡(mysql_error());现在,我想传递一个变量,并在用户名为该变量值时检索行。您应该使用mysqli而不是mysql,它是最新的表单。但这可能会帮助你开始$USER_NAME=$_请求['username']$Q=mysqli_query($conn,“从
portfolio
WHERE
Username
=“$USER_NAME”中选择*);如果(mysqli_num_rows($Q)>0){//echo“用户名已经存在”}否则{do code}这个框很难显示所有正确的编码,所以如果你看不懂,就发布一个新问题的链接,我可以把它放在那里。没问题,我总是看到其他人在这里讨论复杂的事情,我主要做PHP工作,所以我选择最简单的方法,而不是最难的最编码的方法。很高兴你成功了我还有一个问题。在我的php文件中,我正在运行