gpt4 book ai didi

java - 无法从 api 获取任何响应 (Volley)

转载 作者:太空宇宙 更新时间:2023-11-04 09:44:36 25 4
gpt4 key购买 nike

我无法解析来自 url 的请求 http://shikshan.indiansmarthub.co.in/api/menu_t.php?token=SHIK9306488&catt=3

我的其他 Api 遵循相同的结构,但在将其集成到我的应用程序中时,我无法从此 API 获得任何响应。

Android Volley 代码

private void doLogin() {
String url = "http://shikshan.indiansmarthub.co.in/api/menu_t.php?token=SHIK9306488&catt=3";
StringRequest strReq = new StringRequest(
Request.Method.POST, url,
new Response.Listener<String>() {

@Override
public void onResponse(String response) {

Log.e("tag_r", "tag_r");
Log.e("tag_res", response);

}
},
new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError volleyError) {
Toast.makeText(Login.this, volleyError.getMessage().toString(), Toast.LENGTH_LONG).show();

}
});

//Creating a Request Queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
//Adding request to the queue
requestQueue.add(strReq);
}

API代码


<?php
include("connection.php");
include("connect.php");
ini_set('error_reporting', E_STRICT);
$token=$_GET['token'];

$cat=$_GET['catt'];
if (!$DEVICE) {
if($token=="SHIK9306488")
{

if($cat==2)
{

$m1['MenuName']="Attendance";
$m1['Type']="M";

$m2['MenuName']="Attendance Status";
$m2['Type']="A";
// Leave
$m3['MenuName']="Leave";
$m3['Type']="M";

$m4['MenuName']="Apply Leave";
$m4['Type']="A";

$m5['MenuName']="Leave Status";
$m5['Type']="A";
// Assignment
$m6['MenuName']="Assignment";
$m6['Type']="M";

$m7['MenuName']="Upload Assignment";
$m7['Type']="A";

$m8['MenuName']="Download Assignment";
$m8['Type']="A";

// Exit Option
$m9['MenuName']="Exit";
$m9['Type']="M";

$status['Status']="1";

$data1['getMenu']=array($m1,$m2);
$data2['getMenu']=array($m3,$m4,$m5);
$data3['getMenu']=array($m6,$m7,$m8);
$data4['getMenu']=array($m9);
$data5['Status']=array($status);

$main['Status']="1";
$main['data']=array($data1,$data2,$data3,$data4);


echo json_encode($main);

}
else if($cat==3)
{

$m1['MenuName']="Attendance";
$m1['Type']="M";

$m2['MenuName']="Mark Self Attendance";
$m2['Type']="A";

$m9['MenuName']="Mark Student Attendance";
$m9['Type']="A";

$m10['MenuName']="Attendance Status";
$m10['Type']="A";
// Leave
$m3['MenuName']="Leave";
$m3['Type']="M";

$m4['MenuName']="Apply Leave";
$m4['Type']="A";

$m5['MenuName']="Leave Status";
$m5['Type']="A";

$m11['MenuName']="Leave Approval";
$m11['Type']="A";
// assignment
$m6['MenuName']="Assignment";
$m6['Type']="M";

$m7['MenuName']="Upload Assignment";
$m7['Type']="A";

$m8['MenuName']="Download Assignment";
$m8['Type']="A";

//$m12['MenuName']="Assignment Approval";
//$m12['Type']="A";

// Exit Option
$m13['MenuName']="Exit";
$m13['Type']="M";

$status['Status']="1";

$data1['getMenu']=array($m1,$m2,$m9,$m10);
$data2['getMenu']=array($m3,$m4,$m5,$m11);
$data3['getMenu']=array($m6,$m7,$m8);
$data4['getMenu']=array($m13);
$data5['Status']=array($status);


$main['Status']="1";
$main['data']=array($data1,$data2,$data3,$data4);

echo json_encode($main);

}

else
{
$data=array(response=>"Invalid_token",staus=>0);
$data2=array($data);
$myJson=json_encode($data2);
echo $myJson;
}
}
else
{
$data=array(response=>"Invalid_token",status=>"0");
$data2=array($data);
$myJson=json_encode($data2);
echo $myJson;

}
}
else
{
echo $useragent;
echo "hello";
}

?>


API 已成功命中 postman 和浏览器,但 android 上的 volley 无法命中此 api。

对 postman 的回复

{
"Status": "1",
"data": [
{
"getMenu": [
{
"MenuName": "Attendance",
"Type": "M"
},
{
"MenuName": "Mark Self Attendance",
"Type": "A"
},
{
"MenuName": "Mark Student Attendance",
"Type": "A"
},
{
"MenuName": "Attendance Status",
"Type": "A"
}
]
},
{
"getMenu": [
{
"MenuName": "Leave",
"Type": "M"
},
{
"MenuName": "Apply Leave",
"Type": "A"
},
{
"MenuName": "Leave Status",
"Type": "A"
},
{
"MenuName": "Leave Approval",
"Type": "A"
}
]
},
{
"getMenu": [
{
"MenuName": "Assignment",
"Type": "M"
},
{
"MenuName": "Upload Assignment",
"Type": "A"
},
{
"MenuName": "Download Assignment",
"Type": "A"
}
]
},
{
"getMenu": [
{
"MenuName": "Exit",
"Type": "M"
}
]
}
]
}

最佳答案

Api 代码中的 $DEVICE 变量存在问题。这就是返回 useragent 和 hello 关键字的原因。您的 API 在 PC 上工作正常,但在移动浏览器上工作不正常。

检查Screenshot

关于java - 无法从 api 获取任何响应 (Volley),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55574917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com