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];
  • 写回答

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里