在目标c中从iphone应用程序将数据发送到PHP [英] send data to PHP from iphone app in objective c

查看:32
本文介绍了在目标c中从iphone应用程序将数据发送到PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

感谢任何帮助.

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

推荐答案

在将数据发送到 PHP 块之前,JSON 在 Objective-c 中对数据进行编码.这也应该处理可能传递的任何空间.

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.

即.NSString* stringData = [[NSString alloc] initWithData:yourData编码:NSUTF8StringEncoding];

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

这篇关于在目标c中从iphone应用程序将数据发送到PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆