【问题标题】:Php file_get_contents returning empty resultphp file_get_contents 返回空结果
【发布时间】:2021-09-15 00:16:49
【问题描述】:

我正在尝试使用 API 将发布的(应用程序/json)数据接收到我的 Php 项目。

我的 PHP 项目文件位于那里:

v1/project/index.php

$request = file_get_contents('php://input');

当我像这样使用 API url 时:

[POST] localhost/v1/project/

它正在工作。但是:

[POST] 本地主机/v1/项目

不工作。 我想在 URL 的末尾不带斜线共享这个 API。我该如何解决?

【问题讨论】:

  • 只使用.htaccess 重定向
  • 这是一个 HTTP 服务器配置,使用 localhost/v1/project 您尝试发布到文件项目,而 localhost/v1/project/ 在项目目录中查找索引

标签: php api post file-get-contents


【解决方案1】:

谢谢大家,通过 .htaccess 重定向解决了(谷歌:非斜线到斜线重定向)。

<IfModule mod_rewrite.c>

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

</IfModule>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-09
    • 2015-01-24
    • 2022-01-08
    • 2013-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多