Note that there are some explanatory texts on larger screens.

plurals
  1. POServlet does not receive the post parameters after Redirect (Response code 302)
    primarykey
    data
    text
    <p>I want to access my web site that first requires a basic authorization, and then post the parameters (search keyword) to my home page.</p> <p>My code can pass the basic authorization and will get the response text, however I cannot get the search result but get the home page code instead.</p> <p>As such, I printed the parameters.size() and it return 0, so I doubt the HttpClient redirect method does not pass the parameters after basic authorization.</p> <p>Following my code, which is trying to get the search result:</p> <pre><code>List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;(); params.add(new BasicNameValuePair("search_keyword", "test")); params.add(new BasicNameValuePair("search_size", "50")); DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setRedirectStrategy(new DefaultRedirectStrategy() { public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException { boolean isRedirect=false; try { isRedirect = super.isRedirected(request, response, context); } catch (ProtocolException e) { throw e; } if (!isRedirect) { int responseCode = response.getStatusLine().getStatusCode(); if (responseCode == 301 || responseCode == 302) { return true; } } return isRedirect; } }); String encoding = Base64Encoder.encode("admin:password"); HttpPost httppost = new HttpPost("http://127.0.0.1/MySystem/home"); httppost.setHeader("Authorization", "Basic " + encoding); httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); //Execute and get the response. HttpResponse response = httpclient.execute(httppost); int responseCode = response.getStatusLine().getStatusCode(); switch(responseCode) { case HttpURLConnection.HTTP_OK: HttpEntity entity = response.getEntity(); List&lt;NameValuePair&gt; parameters = new ArrayList&lt;NameValuePair&gt;(URLEncodedUtils.parse(entity)); System.out.println("parameters size: "+parameters.size()); for(NameValuePair p:parameters) System.out.println("parameter: "+ p.getName() + p.getValue()); if(entity != null) { responseText = EntityUtils.toString(entity); System.out.println("responseText: "); System.out.println(responseText); } break; default: throw new Exception("Failed to pass the basic authorization. Response code: "+responseCode); } </code></pre> <p>Updated:</p> <p>The following condition will return true:</p> <pre><code>if (responseCode == 301 || responseCode == 302) { return true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload