Note that there are some explanatory texts on larger screens.

plurals
  1. POHTTPClient redirect when using POST method
    primarykey
    data
    text
    <p>I have a site that redirect me to another site with this php code:</p> <pre><code>&lt;?php header("Location: new.php?id=".$_POST["id"]."&amp;test=".rand(5,15)); echo "35"; ?&gt; </code></pre> <p>-new.php</p> <pre><code>&lt;?php echo "ID: ".$_GET["id"]."| TEST: ".$_GET["test"]; ?&gt; </code></pre> <p>If I try to send a Post request with the HTTPClient, the site doesn't redirects me to the other site (response of the post request is 35). It works perfectly fine when I send a Get request. the response of the request is ID: | TEST: 13.</p> <p>-http.java</p> <pre><code>public class Http { public static void main(String[] args) { HttpResponse response; CloseableHttpClient client = HttpClients.createDefault(); HttpPost post = new HttpPost("http://localhost/test.php"); try { List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(1); nameValuePairs.add(new BasicNameValuePair("id","55")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader( response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } try { HttpGet get = new HttpGet("http://localhost/test.php"); response = client.execute(get); BufferedReader rd = new BufferedReader(new InputStreamReader( response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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