来自CURL的成功JSON响应 - 没有来自RESTClient / HttpRequester的JSON响应

时间:2015-01-27 21:51:00

标签: php ios json curl request

我正在尝试修复服务器端问题(我认为) - 我必须要做的唯一真正的线索是当我从终端使用curl时 - 我得到了正确的JSON响应。当我使用RESTClientHttpRequester时(这些都是浏览器的插件来测试请求)我不会得到一个空的但成功的回复。这一切都与我正在创建一个iOS应用程序的事实相关,并且在该应用程序中 - 当我尝试使用RESTClientHttpRequester发出请求时,我遇到了相同的结果 - 没有JSON ,但成功的请求。

我在想如果我可以获得使用RESTClientHttpRequester的请求,那么它将适用于我的iOS应用(我的iOS应用也存在接收空JSON响应的问题)。

我正在为我的服务器端代码(PHP)寻找调试策略 - 如果有人想看到它的任何一个请问 - 我想知道这是否可以通过更改设置来修复我的php.ini文件。

非常感谢任何帮助。

更新 服务器端代码(PHP):

<?php
require __DIR__.'/../../autoload.php';

function getStatusCodeMessage($status)
{
    // these could be stored in a .ini file and loaded
    // via parse_ini_file()... however, this will suffice
    // for an example
    $codes = Array(
        100 => 'Continue',
        101 => 'Switching Protocols',
        200 => 'OK',
        201 => 'Created',
        202 => 'Accepted',
        203 => 'Non-Authoritative Information',
        204 => 'No Content',
        205 => 'Reset Content',
        206 => 'Partial Content',
        300 => 'Multiple Choices',
        301 => 'Moved Permanently',
        302 => 'Found',
        303 => 'See Other',
        304 => 'Not Modified',
        305 => 'Use Proxy',
        306 => '(Unused)',
        307 => 'Temporary Redirect',
        400 => 'Bad Request',
        401 => 'Unauthorized',
        402 => 'Payment Required',
        403 => 'Forbidden',
        404 => 'Not Found',
        405 => 'Method Not Allowed',
        406 => 'Not Acceptable',
        407 => 'Proxy Authentication Required',
        408 => 'Request Timeout',
        409 => 'Conflict',
        410 => 'Gone',
        411 => 'Length Required',
        412 => 'Precondition Failed',
        413 => 'Request Entity Too Large',
        414 => 'Request-URI Too Long',
        415 => 'Unsupported Media Type',
        416 => 'Requested Range Not Satisfiable',
        417 => 'Expectation Failed',
        500 => 'Internal Server Error',
        501 => 'Not Implemented',
        502 => 'Bad Gateway',
        503 => 'Service Unavailable',
        504 => 'Gateway Timeout',
        505 => 'HTTP Version Not Supported'
    );

    return (isset($codes[$status])) ? $codes[$status] : '';
}

// Helper method to send a HTTP response code/message
function sendResponse($status=null, $body = '')
{
    $status_header = 'HTTP/1.1 ' . $status . ' ' . getStatusCodeMessage($status);
    header('Content-type: text/html');
    header($status_header);
    echo $body;
}

//$found = false;

class Getcomment {
    private static $db = null;
    private static $db2 = null;
    private $cryptor;
    private $password;
    //public $public = null;
    //public $dr = null;
    //public //$this->emailpub = null;
    //public //$this->emailpub1 = null;
    //public $gothere = null;
    private $querystring;
    private $stforquee;
    private $hh;
    //private $this->plaintextemail = "";
    private $usah;
    //private $newstring = "";

    private $arrayfordat;

    private $email;
    private $pass;

    private $plaintextemail;
    private $plaintextusername;
    private $didmakeaccount;
    private $passw;
    private $emailif;
    private $username;



    private $forupp;

    // Constructor - open DB connection
    function __construct() {
        $dsn = 'mysql:dbname=mappoints;host=localhost;port=3306';
        $username = 'root';
        $password = 'bonjour3';
        try {
            self::$db = new PDO($dsn, $username, $password); // also allows an extra parameter of configuration
            self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        } catch(PDOException $e) {
            //echo "\n\n\n\nerror\n\n\n\n".$e."\n\n\n\nerror\n\n\n\n";
            die('Could not connect to the database:<br/>' . $e);
        }
    }

    // Destructor - close DB connection
    function __destruct() {
        //self::$db->close();
    }

    function getcomment() {
        $this->cryptor = new \RNCryptor\Decryptor();
        $this->password = "jackbenimble";
        $this->querystring ="";
        $this->stforquee="";
        $this->hh="";
        $this->forupp = "";
        //$this-> $this->plaintextemail = "";
        $this->usah = array();
        $this->forencode = array();

        //$this-> $newstring = "";
        $this->arrayfordat = array();

        /*$this->email = "";
        $this->email="";
        $this->firstname="";
        $this->lastname="";
        $this->logintime="";
        $this->gender="";
        $this->verified="";
        $this->timezone="";
        $this->link="";
        $this->locale="";
        $this->iddd="";*/
        if(isset($_POST["username"])){
            $this->username = $_POST["username"];

            $base64Encrypted13 = preg_replace('/\s+/', '+', $this->username);
            $this->username = $this->cryptor->decrypt($base64Encrypted13, $this->password);


        //$this->newstring .= "s";
        }
        if(isset($_POST["snippet"])) {
            $snippet = $_POST["snippet"];
            $snippet1 = $snippet;

            $stmt = self::$db->prepare("SELECT comment, founder AS something FROM mapPoints, comments WHERE comments.attachedto=:snippet AND mapPoints.mapPointStory=:snippet1 ORDER BY comments.id DESC");
            $stmt->bindValue(':snippet', $snippet, PDO::PARAM_STR);
            $stmt->bindValue(':snippet1', $snippet1, PDO::PARAM_STR);

            //$stmt->bindValue(':snippet1', $snippet1, PDO::PARAM_STR);
            //$stmt->bindValue(':name', $name, PDO::PARAM_STR);
            if($stmt->execute()) {

            //echo "\n\n\n\n\nhere2\n\n\n\n";

                $this->usah = $stmt->fetchAll();

                //$sendit = json_encode($this->usah);

                return $this->usah;
            }
            else {
                return 4;
            }

            //DO MORE HERE
        }
    }
}

$api11 = new Getcomment;
//print "SCHMECKO\n\n";
//$token1 = givetoken();

$jack11 = $api11->getcomment();

if(is_int($jack11)) {

    sendResponse(404);
    return false;

}
else {

    sendResponse(202, json_encode($jack11));
    return true;
}
?>

0 个答案:

没有答案