1

I'm using volley with callback interface. I'm send post request to server and server response 302 status code. How to set location in responsed header to variable string type? Then i want start new activity with full screen webview with this location.

this code in volley classes send requests:

public StringPostRequest(Context context, String url, Map<String, String> params) {
    this.params = params;
    this.url = url;
    mQueue = Volley.newRequestQueue(context, new NukeSSLCerts());
    }

public void getString(final VolleyCallback callback) {
    StringRequest stringRequest = new StringRequest(Request.Method.POST, url ,
            new Response.Listener<String>(){
                @Override
                public void onResponse(String response) {
                    req = response;
                    callback.onSuccess(req);

                }
            }
            ,new Response.ErrorListener(){
                @Override
                public void onErrorResponse(final VolleyError error){
                final int status = error.networkResponse.statusCode;
                // Handle 30x
                if(HttpURLConnection.HTTP_MOVED_PERM == status || status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_SEE_OTHER) {
                    final String location = error.networkResponse.headers.get("Location");
                    callback.onSuccess(location);

                }
            }
    })
    {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            return params;
        }
    };
    mQueue.add(stringRequest);
}
public interface VolleyCallback{
    void onSuccess(String req);
}

In Main activity i'm creating Map for Post Request.

 Map<String,String> params = new HashMap<>();
    params.put("foo", "bar");
    params.put("foo1", "bar1");
    params.put("foo2", "bar2");

    StringPostRequest getRedirectUrl = new StringPostRequest(this,url,params);
    getRedirectUrl .getString(new StringPostRequest.VolleyCallback() {
        @Override
        public void onSuccess(String req) {
            Log.d("reqInMainact", req);
            RedirectUrl[0] = req;
        }
    });
    return RedirectUrl[0];

But Location in response header not write to RedirectUrl[0] (( Help me please

viik_ufa
  • 11
  • 3

2 Answers2

0

But Location in response header not write to RedirectUrl[0]

I'm sure it did, but you wrote your asynchronous code as if it was synchronous.

Make whatever method that has return RedirectUrl[0]; be void, and try this

StringPostRequest getRedirectUrl = new StringPostRequest(this,url,params);
getRedirectUrl.getString(new StringPostRequest.VolleyCallback() {
    @Override
    public void onSuccess(String req) {
        Log.d("reqInMainact", req);

        Intent i = new Intent(CurrentActivity.this, NewActivity.class);

        i.putExtra("URL",req);
        startActivity(i);
    }
});

Then i want start new activity with full screen webview with this location

More details:

How do I pass data between Activities in Android application?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
-1

I doing easy ))) I'm start webview with old url and get redirect in WebView ) Thanks all and sorry

viik_ufa
  • 11
  • 3