dssk35460
2014-11-20 13:52
浏览 49
已采纳

为什么我不能在IOS应用程序中使用NSURLConnection使用php页面将记录重新添加到数据库?

I have a simple php page that takes as argument, via GET, some parameters. These parameters represent a string value to put in a database online and a condition: if it had to be inserted or deleted (parameter insert=1 then insert, parameter delete=1 then delete). The page gets called in this way:

http://www.example.com/save_string.php?string=6&insert=1 OR http://www.example.com/save_string.php?string=6&delete=1

When i call it by my browser it works perfectly. When i call it by my ios app i see a strange behaviour. It happens if i call, even in separate moments of time but sequentially:

http://www.example.com/save_string.php?string=6&insert=1 OK
http://www.example.com/save_string.php?string=6&delete=1 OK
http://www.example.com/save_string.php?string=6&insert=1 NOT WORKING

I mean, if i call it to insert a value, it works perfectly. Then if i call it to delete the same value, it works perfectly. Then i if i call it to insert the same value i deleted it doesn't insert it anymore. Not even if i call it a thousand times. But if i get back to my pc and my browser and i call the url ios is calling again and again with no result, it works perfectly. I hope i explained myself for it is so nonsense to me that i can't do better. Here's my php and objective C code, pretty simply really.

string.php

<?php 
$string=$_GET['string'];
$insert=$_GET['insert'];
$delete=$_GET['delete'];

if($insert){
    $qry = "INSERT INTO SOMETABLE (SOMEFIELD) VALUES (".$string.")";
}

if($delete){
    $qry = "DELETE FROM SOMETABLE";
}
    $rs = connetti($qry);
?>

Ios code

NSString *urlString = @"http://www.example.com/save_string.php?string=6&insert=1";
NSString *escapedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *urlLink = [NSURL URLWithString:escapedString];
NSLog(@"!%@!",urlLink);

NSURLRequest *request = [NSURLRequest requestWithURL: urlLink cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0];

图片转代码服务由CSDN问答提供 功能建议

我有一个简单的php页面,通过GET作为参数,一些参数。 这些参数表示要在线放入数据库的字符串值和条件:如果必须插入或删除(参数insert = 1则insert,参数delete = 1则删除)。 以这种方式调用页面:

  http://www.example.com/save_string.php?string=6&insert=1或http:// www。  example.com/save_string.php?string=6&delete=1
nn

当我通过浏览器调用它时效果非常好。 当我通过我的电话调用它时 ios app我看到一个奇怪的行为。 如果我打电话,即使是在不同的时刻,也会顺序地发生这种情况:

  http://www.example.com/save_string.php?string=6&insert=1  OK 
http://www.example.com/save_string.php?string = 6&amp; delete = 1 OK 
http://www.example.com/save_string.php?string = 6&amp; insert = 1 NOT WORKING 
    
 
 

我的意思是,如果我调用它来插入一个值,它就可以完美地运行。 然后,如果我将其称为删除相同的值,它将完美地工作。 然后我,如果我称之为插入相同的值,我删除它不再插入它。 即使我把它称之为一千次也没有。 但是,如果我回到我的电脑和我的浏览器,我打电话给网址ios一次又一次地呼叫没有结果,它完美的工作。 我希望我解释自己因为我无法做得更好。我这是我的php和客观C代码,非常简单。

string.php

 &lt;?php 
 $ string = $ _ GET ['string']; 
 $ insert = $ _ GET ['insert']; 
  $ delete = $ _ GET ['delete']; 
 
if($ insert){
 $ qry =“INSERT INTO SOMETABLE(SOMEFIELD)VALUES(”。$ string。“)”; 
} 
 
if  ($ delete){
 $ qry =“DELETE FROM SOMETABLE”; 
} 
 $ rs = connetti($ qry); 
?&gt; 
   
 
 <  p>  Ios代码  
 
 
  NSString * urlString = @“http://www.example.com/save_string.php?string=6&insert  = 1“; 
NSString * escapedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
NSURL * urlLink = [NSURL URLWithString:escapedString]; 
NSLog(@”!%@!“,urlLink); 
 
NSURLRequest * request = [  NSURLRequest requestWithURL:urlLink cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0]; 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongmuyuan3046 2014-11-20 14:13
    已采纳

    I'm not an iOS expert but I think that here is a cache issue.. you may try changing the cachePolicy to NSURLRequestReloadIgnoringCacheData

    点赞 评论

相关推荐 更多相似问题