hay guys, I am trying to send a word/text from my iphone application to php page any idea......?
Thanks in advance
hay guys, I am trying to send a word/text from my iphone application to php page any idea......?
Thanks in advance
You would just have to load the URL with the word / text as a parameter using NSURLConnection
. See the following for help in using NSURLConnection
:
And, some sample code:
// The word
NSString wrd = [NSString stringWithString:@"hello"];
// Create the request.
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.yourdomain.com/thepage.php?word=@%", wrd]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
receivedData = [[NSMutableData data] retain];
} else {
// Inform the user that the connection failed.
}
You might do it with an asynchronous call.
// Prepare the URL
NSString myWord = @"YOUR_WORD";
NSString *urlString = [NSString stringWithFormat:@"http://<YOUR_DOMAIN>/<YOUR_FILE>.php?word=%@", myWord];
NSURL *url = [NSURL URLWithString:urlString];
// Get the data from the URL
NSURLRequest *request = [[NSURLRequest alloc] initWithURL: url];
// If you want to get an answer from this call then send "self" as delegate
// (and implement few NSURLConnectionDelegate methods),
// otherwise send "nil".
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection release];
[request release];
You might also send the word synchronously:
// Prepare the URL
NSString myWord = @"YOUR_WORD";
NSString *urlString = [NSString stringWithFormat:@"http://<YOUR_DOMAIN>/<YOUR_FILE>.php?word=%@", myWord];
// Get the data from the URL
NSError *error;
NSData *aData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:urlString] options:2 error:&error];