Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php JSON fetch dosen';不能在真实主机中正常工作,但可以在本地主机中工作_Php_Android_Android Volley_Host - Fatal编程技术网

Php JSON fetch dosen';不能在真实主机中正常工作,但可以在本地主机中工作

Php JSON fetch dosen';不能在真实主机中正常工作,但可以在本地主机中工作,php,android,android-volley,host,Php,Android,Android Volley,Host,我的免费主机中有这个json: 正如您所看到的,如果在浏览器中运行此操作并获取两个参数,则获取工作正常。但是当把这个url放在我的android应用程序(截取)中时,不会获取任何内容。在上一篇文章中,当我在本地主机(xampp)中使用这个json时,一切都正常工作,但是当释放主机时,这个问题出现了 dbconfig.php <?php //Define your host here. $servername = "xxx"; //Define your database username

我的免费主机中有这个
json

正如您所看到的,如果在浏览器中运行此操作并获取两个参数,则获取工作正常。但是当把这个url放在我的android应用程序(截取)中时,不会获取任何内容。在上一篇文章中,当我在本地主机(xampp)中使用这个json时,一切都正常工作,但是当释放主机时,这个问题出现了

dbconfig.php

<?php
//Define your host here.
$servername = "xxx";
//Define your database username here.
$username = "xxx";
//Define your database password here.
$password = "*******";
//Define your database name here.
$dbname = "xxx";
?>
<?php 

include 'dbconfig.php';

$con = mysqli_connect($servername,$username,$password,$dbname);
 //creating a query
 $stmt = $con->prepare("SELECT POWER , ONE_THRUST_BEARING_METAL_TEMP

 FROM turbine_table ORDER BY id DESC LIMIT 1;");

 //executing the query 
 $stmt->execute();

 //binding results to the query 
 $stmt->bind_result($t1,$t2);

 $boiler = array(); 

 //traversing through all the result 
 while($stmt->fetch()){
 $temp = array();

$temp['t1'] = $t1;
$temp['t2'] = $t2;

 array_push($boiler, $temp);
 }

 //displaying the result in json format 
 echo json_encode($boiler);
 ?>

fetch_turbine2.php

<?php
//Define your host here.
$servername = "xxx";
//Define your database username here.
$username = "xxx";
//Define your database password here.
$password = "*******";
//Define your database name here.
$dbname = "xxx";
?>
<?php 

include 'dbconfig.php';

$con = mysqli_connect($servername,$username,$password,$dbname);
 //creating a query
 $stmt = $con->prepare("SELECT POWER , ONE_THRUST_BEARING_METAL_TEMP

 FROM turbine_table ORDER BY id DESC LIMIT 1;");

 //executing the query 
 $stmt->execute();

 //binding results to the query 
 $stmt->bind_result($t1,$t2);

 $boiler = array(); 

 //traversing through all the result 
 while($stmt->fetch()){
 $temp = array();

$temp['t1'] = $t1;
$temp['t2'] = $t2;

 array_push($boiler, $temp);
 }

 //displaying the result in json format 
 echo json_encode($boiler);
 ?>

java

StringRequest stringRequest1=new StringRequest(Request.Method.GET,"http://alibhm.epizy.com/fetch_turbine2.php",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONArray array=new JSONArray(response);
                        for (int i=0; i < array.length(); i++) {
                            JSONObject product=array.getJSONObject(i);

                            String b1=product.getString("t1");
                            String b2=product.getString("t2");

                            final TextView a1=findViewById(R.id.pf1);
                            final TextView a2=findViewById(R.id.pf2);

                            a1.setText(b1);
                            a2.setText(b2);

                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                }
            });
    Volley.newRequestQueue(this).add(stringRequest1);
StringRequest stringRequest1=新的StringRequest(Request.Method.GET)http://alibhm.epizy.com/fetch_turbine2.php",
新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
试一试{
JSONArray数组=新的JSONArray(响应);
对于(int i=0;i
一周后,我找到了答案:)我的代码没有问题。一切都是由一些免费的主机保护造成的。一些免费主机具有防机器人程序的保护。我的应用程序称为此主机的bot。我换了主人,一切都像魅力一样。我建议使用付费主机来传递问题。

您调试过吗?json字符串是否来自请求?调试以查看您得到的响应字符串,从中您可能会了解出了什么问题您是说在android studio中调试?logcat的哪一部分显示了这一点?我想我的问题来自我的主人,但为什么?我不知道。因为它在我的本地主机中工作正常