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

  • Blue Lightning TV

    Blue Lightni

    9 EKİM 2011
  • Canal TekZoom

    Canal TekZoo

    1 NİSAN 2012
  • SuppressedStorm

    SuppressedSt

    11 AĞUSTOS 2013