【问题标题】:PHP API not receiving any data from android app and API testing applicationPHP API 未从 android 应用程序和 API 测试应用程序接收任何数据
【发布时间】:2016-11-12 13:47:08
【问题描述】:

我已经为安卓应用创建了 API。我试图从 android 应用程序以及桌面上的一些 API 测试应用程序发送数据,但我的 API 没有从这些应用程序接收任何数据。我不知道问题出在 API 代码或 htaccess 文件中
以下是我的 API 的 PHP 代码:

<?php
  $data = $_POST;
  print_r($data);  
?>


我也使用过file_get_contents("php://input");,但它不起作用

上述代码的输出如下:

数组();

下面是我的htaccess文件代码

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
            Options -MultiViews
        </IfModule>

        RewriteEngine On


    RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

        # Redirect Trailing Slashes...
        RewriteRule ^(.*)/$ /$1 [L,R=301]

        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]



</IfModule>

Followign 是我保存所有 API 文件的目录路径:
http://domain.com/API
API是目录

我的 htacess 代码或 API 有什么问题

【问题讨论】:

  • 我想,改变这个:

标签: php android .htaccess api mod-rewrite


【解决方案1】:

使用 API 调试,您最好将调试数据附加到服务器端的日志中,而不是将响应打印回客户端。这样做很简单:

file_put_contents('api.log', print_r($_SERVER, true) . print_r($_POST, true), FILE_APPEND);

如果您在 Android 上使用 Cordova 之类的东西,请确保允许它在白名单中访问您的 API。只需确保它可以通过获取其他内容(例如随机 Google 搜索)来建立您所期望的连接。

【讨论】:

    猜你喜欢
    • 2012-05-05
    • 2013-05-13
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 2015-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多