将数据从目标c中的iphone应用程序发送到PHP


send data to PHP from iphone app in objective c

我有一个应用程序,它需要将数据发送到mysql以插入到我的表中。所以我使用PHP来实现这一点。但问题是,我无法发送中间有空格的数据。我怎样才能做到这一点?我需要用xml/JSON编码数据吗?或者还有其他方法吗?如果我需要对数据进行编码。。我该怎么做?

感谢您的帮助。

PHP代码:

$guesttype = $_GET["guesttype"];
$guestLname =$_GET["guestLname"];
$guestFname =$_GET["guestFname"];
----
echo "something";

目标C代码:

NSString *strURL = [NSString stringWithFormat:PHPurlwithargs ,userName, password, hostName, DBName, function, userCompany, _todisplaytype];
// to execute php code
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
// to receive the returend value
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

JSON在将数据发送到PHP块之前,先用objective-c对数据进行编码。这也应该考虑到任何可能传递的空间。

即。NSString*stringData=[[NSStringalloc]initWithData:yourData编码:NSUTF8StringEncoding];