SORU
25 AĞUSTOS 2010, ÇARŞAMBA


Objective-C örnek post http basit?

Bir oturum açma (kullanıcı kimliği ve şifre) gerektiren bir php web sayfası var. Ben kullanıcı sadece iyi app.. içine bilgileri girin ama bir web sitesi için bir POST isteği yapmak için nasıl bir örnek istiyorum. Destek sitesinde apple örneği oldukça karmaşık resim upload.. bana bir mesaj at.. 2 satır yazı yazmak.. basit olması gerektiğini gösteriyor Herkes herhangi bir iyi örnekler var mı?

Alex

CEVAP
25 AĞUSTOS 2010, ÇARŞAMBA


Hakkında

NSString *post = @"key1=val1&key2=val2";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://www.nowhere.com/sendFormHere.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

http://deusty.blogspot.com/2006/11/sending-http-get-and-post-from-cocoa.html alınan . Geçenlerde kullanılan bir şey değil, ve benim için iyi çalıştı.

Btw googling saniye aynı sonucu terimler kullanarak izin vermezdi "post isteği kakao" ;)

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Nightmare2005

    Nightmare200

    14 Ocak 2007
  • Music EuroDance 2

    Music EuroDa

    12 Mayıs 2011
  • Sarah's YouTube Channel

    Sarah's YouT

    27 Temmuz 2009