$ _POST Values ​​Gone After SSL Enabled

In android, I am trying to send a web server to a json structure. It works great with http. But with https, the pairs of $ _POST values ​​have disappeared. In PHP, var_dump $ _POST returns an array (0). However, HttpGet works well with both http and https.

MyHttpClient httpClient = new MyHttpClient(context); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); 
0
source share
2 answers

Try to catch the original message data in php.

 $data = file_get_contents('php://input'); 
+1
source

If I install HttpClientParams.setRedirecting (params, false); Then the page returns "Fixed temporary broken link"

It looks like you are sending your request to the http:// URL and are counting on a redirect (perhaps via mod_rewrite or something like that, like redirecting in the PHP code itself) to turn your page into https .

This mode of operation first makes a simple HTTP request to the server, which then tells the client that the resource has moved to https:// . In turn, if automatic redirection is activated, the client makes a second request.

According to the HTTP specification, for status codes 301 or 302 (which are used for redirection),

If the status code 301/302 is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request if it cannot be confirmed by the user, as this can change the conditions under which the request was sent.

Most browsers interpret this as "if the first request was POST, do not forward the data for the redirected request, but make the second GET request anyway." This explains why you are losing the POSTed body for the second attempt.

Please note that for the reasons stated in this answer , over-reliance on rewriting / redirecting to refer the http:// request to the https:// request should be considered bad practice.

+1
source

Source: https://habr.com/ru/post/1402742/


All Articles