レスポンスを処理したいときにも同期の方が便利。
textをPOSTし 、レスポンスをcontentsに。
NSURL *url = [NSURL URLWithString:urlstr];
NSData *myRequestData = [text dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: url];
[request setHTTPMethod: @"POST"];
[request setValue:@"text/html; charset=utf-8" forHTTPHeaderField:@"content-type"];
[request setHTTPBody: myRequestData];
result = NULL;
contents = NULL;
//同期通信
NSURLResponse *resp;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&resp error:nil];
//convert to UTF8 text
contents = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
0 件のコメント:
コメントを投稿