gpt4 book ai didi

php - Volley POST 字符串请求意外错误 500

转载 作者:行者123 更新时间:2023-12-03 15:51:42 25 4
gpt4 key购买 nike

我在我的项目中使用 Volley 库并获得 Unexpected response code 500作为回应。

我已经彻底搜索了 stackoverflow,但仍然找不到有效的解决方案。

以下是我发出 GET 字符串请求的代码

        val API = "http://squadtechsolution.com/android/v1/allcompany.php"
val requestQueue = Volley.newRequestQueue(mActivity)
val stringRequest = StringRequest(
Request.Method.GET,
API,
Response.Listener { response ->
Log.i("dxdiag", response)
mView.onFetchHttpDataResult(true)
Toast.makeText(context, response, Toast.LENGTH_LONG).show()
},
Response.ErrorListener { error ->
Toast.makeText(context, error.toString(), Toast.LENGTH_LONG).show()
Log.i("dxdiag", error.printStackTrace().toString())
mView.onFetchHttpDataResult(false)
})
requestQueue.add(stringRequest)

以下是堆栈跟踪
2019-09-03 17:15:53.237 3308-3892/com.squadtechs.markhor.foodapp 
E/Volley: [194] BasicNetwork.performRequest: Unexpected response code
500 for
http://squadtechsolution.com/android/v1/allcompany.php
2019-09-03 17:15:53.243 3308-3351/com.squadtechs.markhor.foodapp
D/EGL_emulation: eglMakeCurrent: 0xa7d84180: ver 2 0 (tinfo
0xa7d832b0)
2019-09-03 17:15:53.256 3308-3308/com.squadtechs.markhor.foodapp
W/System.err: com.android.volley.ServerError
2019-09-03 17:15:53.257 3308-3308/com.squadtechs.markhor.foodapp
W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:205)2019-09-03 17:15:53.257 3308-3308/com.squadtechs.markhor.foodapp W/System.err: at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:131)2019-09-03 17:15:53.257 3308-3308/com.squadtechs.markhor.foodapp W/System.err: at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111)2019-09-03 17:15:53.257 3308-3308/com.squadtechs.markhor.foodapp W/System.err: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)

以下是我在服务器端编写的 PHP 代码:

<?php
require 'db.php';

$sql = "SELECT * FROM `company_profile`";
$result = $con->query($sql);

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {

$id=$row['id'];

$company_name=$row['company_name'];
$cuisine=$row['cuisine'];
$conpany_phone=$row['conpany_phone'];
$company_description=$row['company_description'];
$company_logo=$row['company_logo'];
$company_type=$row['company_type'];
$delivery_type=$row['delivery_type'];
$delivery_range=$row['delivery_range'];
$delivery_fee=$row['delivery_fee'];
$delivery_pickupinfo=$row['delivery_pickupinfo'];
$address=$row['address'];

$companyData[] = array('id'=> $id,'company_name'=>
$company_name,'cuisine'=> $cuisine,'conpany_phone'=>
$conpany_phone,'company_description'=>
$company_description,'company_logo'=> $company_logo,'company_type'=>
$company_type,'delivery_type'=> $delivery_type,'delivery_range'=>
$delivery_range,'delivery_fee'=>
$delivery_fee,'delivery_pickupinfo'=> $delivery_pickupinfo,'address'=> $address);
}
echo $jsonformat=json_encode($companyData);
} else {
echo "0 results";
}
$conn->close();
?>

最佳答案

我稍微修改了代码并在 postman 中检查了它,它工作正常。

我将 JSON 编码语句从 if 语句中移出。

// output data of each row
while($row = $result->fetch_assoc()) {

$id=$row['id'];

$company_name=$row['company_name'];
$cuisine=$row['cuisine'];
$conpany_phone=$row['conpany_phone'];
$company_description=$row['company_description'];
$company_logo=$row['company_logo'];
$company_type=$row['company_type'];
$delivery_type=$row['delivery_type'];
$delivery_range=$row['delivery_range'];
$delivery_fee=$row['delivery_fee'];
$delivery_pickupinfo=$row['delivery_pickupinfo'];
$address=$row['address'];

$companyData[] = array('id'=> $id,'company_name'=>
$company_name,'cuisine'=> $cuisine,'conpany_phone'=>
$conpany_phone,'company_description'=>
$company_description,'company_logo'=> $company_logo,'company_type'=>
$company_type,'delivery_type'=> $delivery_type,'delivery_range'=>
$delivery_range,'delivery_fee'=>
$delivery_fee,'delivery_pickupinfo'=> $delivery_pickupinfo,'address'=> $address);
}
echo $jsonformat=json_encode($companyData);

$conn->close();

关于php - Volley POST 字符串请求意外错误 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57769684/

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