IPhone开发中的HTTP链接问题

来源:互联网 发布:2014网络女歌手名字 编辑:程序博客网 时间:2024/05/21 00:18

HTTP链接有很多中方法,在这里介绍一个简单的GET链接,以后不断更新

源码source 如下:

   + (NSData *)Get: (NSString *)url{

    NSError    *error = nil;     //create a error intance
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    NSURL *urlURL = [NSURL URLWithString:url];
    NSURLRequest *currentUrlRequest = [NSURLRequest requestWithURL:urlURL];   //make a request
    
    NSData *returnData = [NSURLConnection sendSynchronousRequest:currentUrlRequest returningResponse:nil error:&error];  //conncet and get response,there are  some another methods which you can study by yourself.
    
    if (error) {  
        NSLog(@"%@",[error localizedDescription]);  
        return nil;  
    }
    return returnData;
}


继续连载 下次是文件传输