gpt4 book ai didi

objective-c - NSURLConnection sendSynchronousRequest - 缺少数据

转载 作者:可可西里 更新时间:2023-11-01 04:27:43 26 4
gpt4 key购买 nike

我正在尝试使用同步请求读取文本文件。它不起作用,但我也没有收到任何错误或警告。

谁能告诉我我做错了什么?

NSString *url = @"http://pappons.com/test.txt" ;

NSLog(@"getHTTPData: %@" , url ) ;
NSURLResponse* response = nil;

NSURLRequest* urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

NSData* data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil] ;

NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

NSLog( @"data: %@" , myString ) ;

输出:

2012-06-15 11:33:42.209 FrederikTest[1365:707] getHTTPData: http://pappons.com/test.txt 
2012-06-15 11:33:42.306 FrederikTest[1365:707] data:

最佳答案

传入NSError检查是否发生错误

NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];

关于objective-c - NSURLConnection sendSynchronousRequest - 缺少数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11048292/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com