我正在尝试对网址执行GET请求并获取JSON响应,但是即使我尝试使用 http://和.json后,我仍然收到错误的网址错误扩展程序。在我测试它时,URL在浏览器中运行得非常好,并为Json提供了get参数。我甚至尝试使用try和catch异常包围下面的代码,但这也无济于事。请检查代码和logcat输出并帮助我。
代码:
final String badUrl = "http://acbcs.co/whosonline.php?token="+token+"&gps="+glong+"&gpslat="+glat;
JsonObjectRequest jsonRequest = new JsonObjectRequest
(Request.Method.GET, badUrl , null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// the response is already constructed as a JSONObject!
try {
response = response.getJSONObject("msg");
String site = response.getString("msg");
String theusers = response.getString("online");
if (site.equals("Error adding user!")) {
Toast.makeText(getApplicationContext(), "Server down", Toast.LENGTH_LONG).show();
} else {
int len = getStrings (theusers,":").length;
concat=new String[len];
concat=getStrings (theusers,":");
usern = new String[len];
glatn = new String[len];
for(int i=0;i<3;i++){
String arrtemp[]=new String[getStrings (concat[i]," ").length];;
arrtemp=getStrings (concat[i]," ");
if(arrtemp[i].length()>0) {
usern[i] = arrtemp[0];
glatn[i] = arrtemp[1]+" *"+arrtemp[2];
break;
}
else {
usern[i] = "Your Location";
glatn[i] = glat+" *"+glong;
}
if(togglemap%2==0){
webview.setVisibility(View.GONE);
}
else {
webview.setVisibility(View.VISIBLE);
String removeusern = Arrays.toString(usern).replace("[","");
removeusern = removeusern.replace("]","");
removeusern = removeusern.replace(", null","");
String latx = Arrays.toString(glatn).replace("[","");
latx = latx.replace("]","");
latx = latx.replace(", null","");
String loadUrlz = "http://easytechi.info/multigpss.php?usern="+removeusern +"&glatn="+latx;
webview.loadUrl(loadUrlz);
System.out.println(loadUrlz);
Toast.makeText(getApplicationContext(), loadUrlz, Toast.LENGTH_SHORT).show();
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
Volley.newRequestQueue(PokeChat.this).add(jsonRequest);
LogCat输出:
09-11 19:50:19.283 18494-18997/ E/Volley: [4913] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL
java.lang.RuntimeException: Bad URL
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:144)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
Caused by: java.net.MalformedURLException: Protocol not found:
at java.net.URL.<init>(URL.java:176)
at java.net.URL.<init>(URL.java:125)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:102)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
09-11 19:50:19.990 18494-18998/ E/Volley: [4914] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL
java.lang.RuntimeException: Bad URL
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:144)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
Caused by: java.net.MalformedURLException: Protocol not found:
at java.net.URL.<init>(URL.java:176)
at java.net.URL.<init>(URL.java:125)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:102)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
09-11 19:54:04.878 18494-18999/ E/Volley: [4915] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL
java.lang.RuntimeException: Bad URL
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:144)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
Caused by: java.net.MalformedURLException: Protocol not found:
at java.net.URL.<init>(URL.java:176)
at java.net.URL.<init>(URL.java:125)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:102)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)