从iphone& amp ;;访问在线超薄API IOS应用程序

时间:2017-04-26 16:39:42

标签: ios iphone slim-3

我在 Slim 中开发了简单的API,它存储在Online Server中。当我从浏览器检查它时它工作正常,但是当我从Iphone应用程序检索它时,它显示以下错误:

PeopleAlsoAsk[12607:2219389] Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 500" UserInfo={NSLocalizedRecoverySuggestion="this is index pagpe, Specific questions are retrieved successfully", NSErrorFailingURLKey=http://upvc.pk/test2/public/, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0x608000001060> { URL: http://upvc.pk/test2/public/ }, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x60800003d6c0> { URL: http://upvc.pk/test2/public/ } { status code: 500, headers {
    "Accept-Ranges" = bytes;
    Connection = "Keep-Alive";
    "Content-Encoding" = gzip;
    "Content-Length" = 81;
    Date = "Wed, 26 Apr 2017 12:34:31 GMT";
    Server = LiteSpeed;
    Vary = "Accept-Encoding";
    "X-Powered-By" = "PHP/7.0.17";
} }, NSLocalizedDescription=Expected status code in (200-299), got 500}
2017-04-26 17:34:31.462 PeopleAlsoAsk[12607:2219389] Error function called

我尝试了很多,但一切都是徒劳的。如果有人遇到这个问题,或者知道这个问题,那么请指导我。提前谢谢。

我的代码如下:

公共/ index.php的

<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

require '../vendor/autoload.php'; 

$app = new \Slim\App; 

//Questions Routes
require '../src/routes/questions.php';

$app->run();

路由/ questions.php

<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

$app = new \Slim\App;

//Get All Questions
$app->get('/api/questions', function(Request $request, Response $response){

$questions = "All questions are retrieved successfully";     

        echo json_encode($questions);

});

// Get specific Questions
$app->get('/api/questions/{app_id}', function(Request $request, Response $response){

$questions = "Specific questions are retrieved successfully";    

echo json_encode($questions);

});

1 个答案:

答案 0 :(得分:1)

你应该把你的iOS代码放在这里。

从你的Slim,我会放置:

CustomData

在您的回复代码中,您可以添加此功能以提供所有客户响应:

$app->status($status_code);

用法非常简单:

function echoResponse($status_code, $response) {
    $app = \Slim\Slim::getInstance();
    // Http response code
    $app->status($status_code);
    // setting response content type to json    
    $app->contentType('application/json');
    echo json_encode($response);
}

从iOS的角度来看,没有代码就很难说些什么。