我想使用 NSURLConnection 从 PHP/Mysql 请求中获取一个值(可以是 1 或 0),下面是我的 xcode 和 php/mysql 查询的代码
谁能帮我将接收到的数据存储在 NSString 而不是 NSMutableData 中?我想使用 NSURLConnection 的原因是因为它提供了无连接功能
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.0.20/iqkradio_stream_ip_flag.php"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:20.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
receivedData = [[NSMutableData data] retain];
NSString *receivedDataString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
}
else
{
NSLog(@"no connection or Error");
// Inform the user that the connection failed.
}
mysql文件
<?php
$con = mysql_connect("192.168.0.15","xxxx","xxxxx");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("qkradio", $con);
$result = mysql_query("select address from iqkradio" );
while($row = mysql_fetch_array($result)) {
echo $row['address'];
}
mysql_close($con);
?>