无需打开页面即可运行PHP文件

时间:2015-06-25 02:18:50

标签: xcode

我需要在不打开互联网浏览器的情况下从我的应用运行PHP文件。我现在正在做的是:

NSString *theUrl = [NSString stringWithFormat:@"http://MyWebSite.com/PHPFile.php?theMessage=%@&theToken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", myString];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:theUrl]];

上面的代码工作正常,但是我需要上网浏览器。 任何人都可以帮助我吗?

由于

1 个答案:

答案 0 :(得分:0)

我找到了答案,但无需打开浏览器就可以了:

 // call the current user
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    NSString *myString = [prefs stringForKey:@"SaveUserName"];
    NSLog(@"User name to delete %@ ",myString);

    NSString *queryString = [NSString stringWithFormat:@"http://MyWebSite.com/phpFile.php?theMessage=%@&theToken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", myString];


    NSURLRequest *theRequest=[NSURLRequest
                              requestWithURL:[NSURL URLWithString:
                                              queryString]
                              cachePolicy:NSURLRequestUseProtocolCachePolicy
                              timeoutInterval:60.0];
    NSURLConnection *con = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    if (con) {
        _receivedData=[NSMutableData data];


    } else {
        //something bad happened
    }

我希望答案对某人有帮助。