これを行うにはNSURLConnection
を使用できます。セットアップ後のデータと他の情報とNSMutableURLRequest
、その後、それを投稿し、応答を取得するためにNSURLConnection
を使用します。
NSString * postString = [NSString stringWithFormat:@"field1=%@", myItem];
NSData * postData = [postString dataUsingEncoding:NSUTF8StringEncoding];
NSURL * myURL = [NSURL URLWithString:@"https://go.urbanairship.com/api/push/broadcast"];
NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:myURL
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:10];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];
NSData * returnedData = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil error:nil];
あなたはまた、非同期要求のためにNSURLConnectionを使用することができます。 NSURLConnection Class Referenceを参照してください。