【发布时间】:2023-04-08 17:29:02
【问题描述】:
我有一个应用程序需要将数据发送到 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];
【问题讨论】:
-
确保您的请求经过正确的 URI 编码,其中空格显示为
%20。对于调试,您可能希望使用像 Charles 这样的代理来检查您的网络调用。如果您是 PHP 新手,请不要尝试从头开始构建这种东西,它非常棘手且容易出错。熟悉popular PHP framework 并利用它们为您编写此类应用程序提供的基础会更好。 -
在objective c和php中使用JSON编码
json_decode($data) -
@dianuj 你能告诉我如何在目标 C 中使用 json 编码数据
标签: php mysql objective-c xml-parsing