send data to PHP from iphone app in objective c

此生再无相见时 提交于 2020-02-08 07:51:46

问题


i have an app which needs to send data to mysql to insert into my tables. So I am using PHP to achieve this. But the problem is that I am not able to send data with spaces in between. How can I achieve this? Do I need to encode the data in xml/JSON or is there any other way? If I need to encode the data..how should I do it?

Any help is appreciated.

PHP code:

$guesttype = $_GET["guesttype"];
$guestLname =$_GET["guestLname"];
$guestFname =$_GET["guestFname"];

----
echo "something";

OBJECTIVE C CODE:

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];

回答1:


JSON encode your data in objective-c before sending it over to your PHP block. That should take care of any spaces that may be passed along as well.

ie. NSString* stringData = [[NSString alloc] initWithData:yourData encoding:NSUTF8StringEncoding];



来源:https://stackoverflow.com/questions/18004566/send-data-to-php-from-iphone-app-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!