如何显示 android 邮政字符串 PHP 服务器上的吗?

标签: json Java Android PHP
发布时间: 2016/10/10 22:34:45
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我正想发送 json 字符串从我 android 我的 php 服务器应用程序。下面是从我的 mobiledb_control.php 和 httpconnect.java 的完整代码

Log.v("HTTPSENDER","WORKED");运行,跟我没有错误。 然而我的 error_log("in");不能运行。

如何做显示 JSON 通过发送 android 到我的 error_log()?

HttpConnect.java:

public class HttpConnect {
    public HttpConnect(){

    }
    public void sendData(String jsonObject){
        try{
            URL url = new URL("http://www.alextanti.net/PHPDashboard/Backend/mobiledb_control.php");
            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
            conn.setRequestMethod("POST");
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setUseCaches(false);

            BufferedWriter output = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream(),"UTF-8"));
            output.write("json="+jsonObject);
            output.flush();
            output.close();
            Log.v("HTTPSENDER","WORKED");
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}

mobiledb_control.php:

   <?php
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set("error_log", "../Logs/error.log");
error_reporting(E_ALL);
if(!empty($_POST['json'])){
  echo(var_dump($_POST['json']));
  error_log($_POST['json']);
}
$headers = apache_request_headers();

?>

解决方法 1:

似乎有固定的它却不知道如何

PHP 文件︰

<?php
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set("error_log", "../Logs/location.log");
error_reporting(E_ALL);
if(!empty($_POST['json'])){
  echo(var_dump($_POST['json']));
  error_log($_POST['json']);
}
?>

JAVA 文件︰

public class HttpConnect {
    public HttpConnect(){

    }
    public void sendData(String jsonObject){
        try{
            URL url = new URL("http://www.alextanti.net/PHPDashboard/Backend/mobiledb_control.php");
            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
            conn.setRequestMethod("POST");
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setUseCaches(false);
            BufferedWriter output = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream(),"UTF-8"));
            output.write("json="+jsonObject);
            output.flush();
            output.close();
            Log.v("HTTPSENDER","WORKED");
            Log.v("HTTPSENDER",""+conn.getResponseCode());
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
赞助商