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

2
  • 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. stackoverflow.com/q/10060152/1224741 Commented Apr 9, 2012 at 1:37
  • Please don't re-ask questions. You can always edit to clarify or add a bounty. See this section in the faq for more information. Commented Apr 9, 2012 at 11:50

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.