使用 Objective-C 执行 PHP 脚本或单向请求



可能的重复项:
使用 objective-c 执行 PHP 脚本

有人可以回顾一下我如何使用ASIHTTPRequest库或NSURLConnection在objective-C中执行单向请求(我不需要任何响应)。是否可以使用 ASIHTTPRequest 异步执行此操作?

另外,这会被视为HTTP POST请求吗?例如,网址类似于这样的 myURL.com/performThisScript.php?specialID=1

代码:

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:@"http://www.yourdomain.com/script.php"];
    NSString *result = (NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)yourData, NULL, CFSTR("?=&+"), kCFStringEncodingUTF8);
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:[result dataUsingEncoding:NSUTF8StringEncoding]];
    [request setHTTPMethod:@"GET"];
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];

提示:

由于 myURL.com/performThisScript.php?specialID=1 在 URL 中暗示参数,因此您应该GET .

最新更新