IPhone kullanan bir PHP bazı argümanlar Gönder

2 Cevap php

Hi I need to send some arguments from the iPhone to a php in the server

PHP:

$text = $_GET['text']);
$mail = $_GET['mail']);
$phone = $_GET['phone']);

iPhone SDK

NSString *text = [[NSString alloc] initWithString:@""]; //very long text
NSString *mail = [[NSString alloc] initWithString:@"any@any.com"];
NSString *phone = [[NSString alloc] initWithString:@"456233876"];

Nasıl PHP bu dizeleri gönderebilirsiniz?

2 Cevap

Burada alanlar "metin", "posta" ve "telefon" post NSURLConnection ile bir HTTP POST isteği oluşturmak istiyorum nasıl:

NSURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.myserver.com/page.php"]];
NSMutableString *postBody = [NSMutableString stringWithFormat:@"text=%@", [@"very long text" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[postBody appendFormat:@"&mail=%@", [@"any@any.com" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[postBody appendFormat:@"&phone=%@", [@"1231231234" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[req setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[req setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
[req setHTTPMethod:@"POST"];
NSURLConnection *conn = [NSURLConnection connectionWithRequest:req delegate:self];

// Now, implement NSURLConnection delegate methods such as connectionDidFinishLoading: and connection:didFailWithError: to do something with the response from the server.

Sadece normal olarak, GET veya POST verileri kullanabilirsiniz. Bu çok basit. Sonra veri göndermek için bir NSURLConnection kullanın ve POST yöntemini değiştirin. Yoksa GET kullanmak ve sadece http://www.mysite.com/mypage.php?var1=abc&var2=def, vb gibi bir URL gönderebilirsiniz

See Using NSURLConnection