简体   繁体   English

STHTTPRequest“和字符”我怎么能将此字符发送到PHP页面?

[英]STHTTPRequest “& char” how i can send this char to a php page?

My ios app have to send/retrive some date throught some php pages. 我的ios应用程序必须通过一些php页面发送/获取一些日期。 This is an example call usingi STHTTPRequest : 这是一个使用STHTTPRequest的示例调用:

 __block STHTTPRequest *up = [STHTTPRequest requestWithURLString:[NSString stringWithFormat:@"%@%@",PATHSERVER,@"retrivedata.php"]];

up.encodePOSTDictionary=NO;
up.postDataEncoding=NSUTF8StringEncoding;

up.POSTDictionary = @{@"name":@"Name", @"surname":@"Surname"};

It's all ok until i decide to insert something lik : 在我决定插入lik之前,一切正常。

up.POSTDictionary = @{@"name":@"Na&me", @"surname":@"Surname"};

In this way a 这样一来

 print_r($_POST);

in retrivedata.php results in: 在retrivedata.php中导致:

Array
(
 [name] => Na
 [surname] => Surname

)

The name is cutted at the "&" char index. 该名称在“&”字符索引处剪切。 I have tried with no success something like: 我尝试了类似的尝试,但没有成功:

utf8_encode/utf8_decode($name)

It seems that name arrives to retrivedata.php already cutted, so i can't use any chars conversion/encoding... In my STHTTPRequest i have already tried to set: 看来到达retrivedata.php的名称已经被切断,所以我不能使用任何字符转换/编码...在我的STHTTPRequest中,我已经尝试设置:

up.encodePOSTDictionary=YES;

With this setting i can send "&" as $amp; 使用此设置,我可以将“&”作为$ amp;发送。 but if i do a SELECT to retrive the value i can't convert it to the normal string by 但是如果我执行SELECT来检索值,则无法通过以下方式将其转换为普通字符串

 html_entity_decode();

it still remain 它仍然存在

&

How i can do? 我该怎么办? My STHTTPRequest send 'Na&me' but it comes blank to $_POST[] in retrivepage.php 我的STHTTPRequest发送'Na&me',但在retrivepage.php中,它对$ _POST []为空

I am not really familiar with the shttprequest, but you should url encode it. 我对shttprequest并不是很熟悉,但是您应该对其进行url编码。 It will look like "Na%26me" when URL encoded. 进行URL编码时,它将看起来像“ Na%26me” Later in the post you will have "Na&me" 稍后,您将看到“ Na&me”

Hope it helps :) 希望能帮助到你 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM