duanqiao1947 2014-07-12 16:47
浏览 67

Objective-c发布请求返回错误

i'm trying to make a simple post request where there is 1 parameter which is the identifierForVendor. For this i'm using the AFNetworking library and php/slim.

The problem is whatever i do i get following error:

Error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: not found (404)" UserInfo=0x16d28630 {NSErrorFailingURLKey=http://LINK,     com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x16d3e470> { URL:     http://LINK } { status code: 404, headers {
    Connection = "Keep-Alive";
    "Content-Length" = 519;
    "Content-Type" = "text/html";
    Date = "Sat, 12 Jul 2014 16:39:17 GMT";
    "Keep-Alive" = "timeout=5, max=100";
    Server = "Apache/2.4.9 (Ubuntu)";
    "X-Powered-By" = "PHP/5.5.12-2+deb.sury.org~precise+1";
} }, NSLocalizedDescription=Request failed: not found (404)}

AFNetworking code:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager POST:@"http://LINK"

   parameters:@{@"udid" : [UIDevice currentDevice].identifierForVendor.UUIDString}
      success:^(AFHTTPRequestOperation *operation, id responseObject) {
          [MBProgressHUD showHUDAddedTo: self.view animated: YES];


          NSLog(@"%@", responseObject);


      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSLog(@"Error: %@", error);
      }];

php/slim code

require 'vendor/autoload.php';


$app = new \Slim\Slim();
$app->get('/getexpired', 'Expired');
$app->run();


 function Expired() {
    $var = $_POST["udid"];
    $sql = "SELECT stores.name, numbers.number, numbers.timestamp, numbers.udid FROM numbers, stores where stores.id = numbers.storeID AND DATE(numbers.timestamp) < CURDATE() AND numbers.udid = '".$var."'";
    try {
        $db = getConnection();
        $stmt = $db->query($sql);
        $wines = $stmt->fetchAll(PDO::FETCH_OBJ);
        $db = null;
        echo '{"match": ' . json_encode($wines) . '}';
    } catch(PDOException $e) {
        echo '{"error":{"text":'. $e->getMessage() .'}}';
    }

}

function getConnection() {
    $dbhost="localhost";
    $dbuser="User";
    $dbpass="pass";
    $dbname="DBNAME";
    $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $dbh;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
    • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序