我使用JSONObject从服务器获取JSON PHP
该代码在 000webhost.com 服务器上运行 fine ,但是当我升级到 hostinger 时,该代码不起作用。 一切在我的COD和PHP上都是正确的,并且与数据库连接良好, 是因为SSL和VPN。 ?? 除非使用其SSL证书,否则JSONObject是否无法正常工作? 是因为链接必须以s HTTPS而不是HTTP开头吗?
String urlConnection ="https://solvable-extension.000webhostapp.com/selectNoty.php"; // Working Fine
String urlConnection = "http://osama.hostingerapp.com/php/selectNoty.php"; // Not Work
请找到两个链接和代码
requestQueue = Volley.newRequestQueue(this);
//String urlConnection ="https://solvable-extension.000webhostapp.com/selectNoty.php"; //Working Fine
String urlConnection = "http://osama.hostingerapp.com/php/selectNoty.php"; //Not Work
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, urlConnection, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("All_users");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject emp = jsonArray.getJSONObject(i);
String name = emp.getString("name");
t1.setText(name);
Log.d("noty_dp", "noty_dp: " + name);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Volley", "Error");
}
});
requestQueue.add(request);
E/Volley: [7552] BasicNetwork.performRequest: Unexpected response code 503 for http://osama.hostingerapp.com/php/selectNoty.php