views:

47

answers:

2

hay guys, I am trying to send a word/text from my iphone application to php page any idea......?

Thanks in advance

A: 

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:

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html#//apple_ref/doc/uid/20001836

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.
}
Chetan
Thanks Chetan em trying it .......
Nauman.Khattak
+1  A: 

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];
Michael Kessler
ok em trying on it will infrom you thanks Michael
Nauman.Khattak
Thanks lot it works.....
Nauman.Khattak