I am using Volley library in my project and getting Unexpected response code 500
as response.
I have searched stackoverflow thoroughly and still unable to find solution that works.
Following is my code for making GET string request
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)
Following is the stacktrace
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)
Following is PHP code that I wrote on server side:
<?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();
?>
Generate Code Snippet
value from postman by clicking theCode
on the right hand side of the software. – RounceUnexpected response code 500
as a response? I just checked your exact code it returns a response without a problem. And tell me your Volley version, please. – Marje<?php // Declare an array $value = array( "name"=>"GFG", "email"=>"[email protected]"); // Use json_encode() function $json = json_encode($value); // Display the output echo($json); ?>
if it doesn't throw an error, then you'll have to make changes in your PHP file to properly encode your response – Marje