NSString *url=@"https://www.thaicreate.com/url/string.php"; NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; NSData *response = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: nil error: nil]; NSString * theString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; lblContent.text = theString;
<?php echo "Server Time = ".date("Y-m-d H:i:s") ?>
// // ViewController.h // NSURLRequestApp // // Created by Weerachai on 12/8/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController { IBOutlet UILabel *lblContent; } - (IBAction)btnGetContent:(id)sender; @end
// // ViewController.m // NSURLRequestApp // // Created by Weerachai on 12/8/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (IBAction)btnGetContent:(id)sender { NSString *url=@"https://www.thaicreate.com/url/string.php"; NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; NSData *response = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: nil error: nil]; NSString * theString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; lblContent.text = theString; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)dealloc { [lblContent release]; [super dealloc]; } @end
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท