url:https://ashish.gupta.in/ins.svc/test/ {abc} / {xyz}
您可以像这样简单地创建请求
科特琳:
fun fetchDataFromAPI(varargs params:String){
val jsonObjectRequest = JsonObjectRequest(Request.Method.GET,
"https://ashish.gupta.in/ins.svc/test/${params[0]}/${params[1]}", null,
Response.Listener { response ->
Log.d("Response",response.toString())
},
Response.ErrorListener { error ->
// TODO: Handle error
}
)
requestQueue.add(jsonObjectRequest ) // use your requestqueue ibject to send the request
}
Java:
void fetchDataFromAPI(String.. params){
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.GET, "https://ashish.gupta.in/ins.svc/test/"+params[0]+"/"+params[1]}, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("Response",response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO: Handle error
}
});
requestQueue.add(jsonObjectRequest); // use your requestqueue ibject to send the request
}
现在您调用类似的函数:
fetchDataFromAPI("1234","lmnop")