在 GET 方法中 url 末尾追加字符串 :Volley
Appending string at the end of url in GET method :Volley
我在 android 应用程序开发中使用 volley 库。
我有一个基础 url,我需要在 url、click here、
的末尾附加一些值
所以,这个值“ZGxb87HuJK”在我的程序中不断动态变化,需要在url的末尾追加这个值。如何在参数中添加这个?
这样使用。
StringRequest strreq = new StringRequest(Request.Method.GET,
"https://sample.com/testing/" + Hear Your dynamic value,
new Response.Listener<String>() {
@Override
public void onResponse(String Response) {
// get response
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError e) {
e.printStackTrace();
}
});
Volley.getInstance(this).addToRequestQueue(strreq);
String URL = "https://sample.com/testing/" + "dynamic value e.g ZGxb87HuJK";
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
URL, null,
new Response.Listener() {
@Override
public void onResponse(JSONObject response) {
//Success Callback
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//Failure Callback
}
});
// Adding the request to the queue along with a unique string tag
MyApplication.getInstance().addToRequestQueue(jsonObjectReq, "getRequest");
像这样更改您的代码
我在 android 应用程序开发中使用 volley 库。
我有一个基础 url,我需要在 url、click here、
的末尾附加一些值所以,这个值“ZGxb87HuJK”在我的程序中不断动态变化,需要在url的末尾追加这个值。如何在参数中添加这个?
这样使用。
StringRequest strreq = new StringRequest(Request.Method.GET,
"https://sample.com/testing/" + Hear Your dynamic value,
new Response.Listener<String>() {
@Override
public void onResponse(String Response) {
// get response
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError e) {
e.printStackTrace();
}
});
Volley.getInstance(this).addToRequestQueue(strreq);
String URL = "https://sample.com/testing/" + "dynamic value e.g ZGxb87HuJK";
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
URL, null,
new Response.Listener() {
@Override
public void onResponse(JSONObject response) {
//Success Callback
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//Failure Callback
}
});
// Adding the request to the queue along with a unique string tag
MyApplication.getInstance().addToRequestQueue(jsonObjectReq, "getRequest");
像这样更改您的代码