NSURLConnection返回(null)值

时间:2013-11-12 22:48:24

标签: php ios sql nsurlconnection

我正在尝试使用PHP

从SQL中的表中提取值列表

以这种方式执行请求:

NSString *post = [NSString stringWithFormat:@"&Auth=%@", Auth];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"path.php"]]];

[request setHTTPMethod:@"POST"];

[request setValue:postLength forHTTPHeaderField:@"Content-Length"];

[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];

[request setHTTPBody:postData];

NSURLResponse *response = nil;
NSError *error = nil;

NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

NSString *Respuesta = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

这是我的PHP代码

    <?php
    $con=mysqli_connect("localhost","user","pass","dbname");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }

    $result = mysqli_query($con,"SELECT * FROM DMARCAS");
        $cadena = "";
    while($row = mysqli_fetch_array($result))
      {
      $cadena .=  $row['U_DMarcaName'] . ", ";

      }
        echo $cadena;

    mysqli_close($con);
    ?>

在浏览器中正常工作但在设备上我得到(null)

我正在运行测试,我认为错误发生在这一行:

如果我更改$ row ['U_DMarcaName']。 ,“”,对于任何字符串,如果结果是正确的。

谢谢。

0 个答案:

没有答案