如何从服务器获取响应后将第二个请求发送到服务器?使用Volley。
我得到了回复,
private void makeStringReq() {
showProgressDialog();
// Instantiate the Request Q
RequestQueue q=Volley.newRequestQueue(this);
StringRequest strReq = new StringRequest(Method.GET,
Const.URL_STRING_REQ, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
msgResponse.setText(response.toString());
hideProgressDialog();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
hideProgressDialog();
}
});
// Add the request to the RequestQueue.
q.add(strReq);
}
我的问题是,一旦我收到服务器的回复,如何发回请求?
感谢。
答案 0 :(得分:0)
private void makeStringReq(String url, int method)
{
showProgressDialog();
// Instantiate the Request Q
RequestQueue q = Volley.newRequestQueue(this);
StringRequest strReq = new StringRequest(method, url, new Response.Listener<String>()
{
@Override
public void onResponse(String response)
{
Log.d(TAG, response.toString());
msgResponse.setText(response.toString());
hideProgressDialog();
makeStringReq(URL_B,Method.POST);
}
}, new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
VolleyLog.d(TAG, "Error: " + error.getMessage());
hideProgressDialog();
}
});
// Add the request to the RequestQueue.
q.add(strReq);
}