Android Studio:JsonObjectRequest在HTTPS
协议下可以正常工作。但是当我尝试使用HTTP时,它会显示错误响应。
private void JSONparse() {
String url="http://ip-api.com/json";
JsonObjectRequest request= new JsonObjectRequest(url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
textView.setText(response.toString());
}catch (Exception e){
textView.setText(e.toString());
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
textView.setText("Error to connect");
}
});
requestQueue.add(request);
}