0

Possible Duplicate:
Executing a PHP script using objective-c

Could somebody go over how I might execute a one way request (I don't need any response), in objective-C using either the ASIHTTPRequest library or NSURLConnection. Is it possible to do this asynchronously using ASIHTTPRequest?

Also, would this be considered an HTTP POST request? The url, for example, is something like this myURL.com/performThisScript.php?specialID=1

Community
  • 1
  • 1
Apollo
  • 8,874
  • 32
  • 104
  • 192
  • A little strange that you asked almost exactly the same question less than 24 hours ago... you can always add to a question and ask for clarification if necessary. http://stackoverflow.com/q/10060152/1224741 – QED Apr 09 '12 at 01:37
  • Please don't re-ask questions. You can always [edit] to clarify or add a bounty. See this section in the [faq#bounty] for more information. –  Apr 09 '12 at 11:50

1 Answers1

0

Code :

    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];

Hint :

Since myURL.com/performThisScript.php?specialID=1 implies parameters in the URL, you should GET.

Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
  • 1
    two questions: 1) does this run asynchronously and 2) I don't need a response from the server so do I still need *result? Thanks – Apollo Apr 09 '12 at 01:43