iphone 实行http post 及多线程编程实例
2010-03-31 17:30:00 来源:WEB开发网#import "FirstUIAppDelegate.h"
@implementation FirstUIAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
//[self postdata];
[self setupThread];
[window makeKeyAndVisible];
}
-(void)setupThread{
[NSThread detachNewThreadSelector:@selector(postdata)toTarget:self withObject:nil];
}
- (void)dealloc {
[window release];
[super dealloc];
}
-(void)postdata{
NSLog(@"TEST");
NSURL *url;
NSMutableURLRequest *urlRequest;
NSMutableData *postBody = [NSMutableData data];
url = [NSURL URLWithString:@"http://allove.org"];
urlRequest = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease];
[urlRequest setHTTPMethod:@"POST"];
NSString *udid = @"phong=15871485145&psw=23";
[postBody appendData:[udid dataUsingEncoding: NSUTF8StringEncoding allowLossyConversion:YES]];
[urlRequest setHTTPBody:postBody];
NSData *returnData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:nil];
if(returnData)
{
NSString *result = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];
NSLog(@"result=======>%@",result);
}
else
{
NSLog(@"Wrong Connetion!");
}
}
@end
- ››iPhone应用帮助残障儿童看图说话
- ››iPhone实用工具AppBox Pro使用教程大揭秘
- ››iphone4省电方法
- ››iphone 获取地址的详细信息
- ››iPhone 库的基本内存管理策略
- ››iPhone加密文字亲手做 私密信息有保障
- ››iphone 根据经纬度坐标取详细地址(包括国,省,市...
- ››iphone/ipad ios cocoa object-c 近期苹果UI部分小...
- ››iphone中如何进行多线程编程
- ››iPhone OS SDK的这些事[安装、下载、版本、实例、...
- ››iPhone ObjectC的NSAutoreleasePool
- ››iPhone 判断设备是在Portrait(纵向)还是(Landscap...
更多精彩
赞助商链接