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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog