gpt4 book ai didi

php - $_POST 值在 SSL 打开后消失

转载 作者:太空宇宙 更新时间:2023-11-03 13:48:44 27 4
gpt4 key购买 nike

在 android 中,我尝试以 json 结构发送到 Web 服务器。它适用于 http。但是有了 https,$_POST 值对就消失了。在 PHP 中,var_dump $_POST 返回 array(0)但是,HttpGet 适用于 http 和 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();

最佳答案

If I set HttpClientParams.setRedirecting(params, false); Then the page returns "Temporary broken link fixed"

听起来您正在将请求发送到 http:// URL 并指望重定向(可能通过 mod_rewrite 或类似的方式,例如重定向PHP 代码本身)将您的页面转换为 https

这种操作模式首先向服务器发出纯 HTTP 请求,然后服务器告诉客户端资源已移动到 https:// 地址。反过来,如果自动重定向被激活,客户端会发出第二个请求。

根据 the HTTP specification, for status codes 301 or 302 (用于重定向),

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

大多数浏览器将此解释为“如果第一个请求是 POST,则不要重新发送重定向请求的数据,但无论如何都要使第二个请求成为 GET”。这可以解释为什么您会在第二次尝试时丢失任何 POSTed 正文。

请注意,由于 this answer 中解释的原因,过度依赖重写/重定向将 http:// 请求转换为 https:// 请求应被视为不良做法。

关于php - $_POST 值在 SSL 打开后消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9456533/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com