gnustep 目标 c 中的简单 http 请求不起作用
#import <Foundation/Foundation.h>
main() {
NSURL *url = [NSURL URLWithString:@"http://www.google.com/"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:60];
NSURLResponse *response;
NSError *error;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"Data were download below:\n%@", [[NSString alloc] initWithData:data encoding: NSASCIIStringEncoding]);
}
运行可执行文件 -> 数据下载如下: [空]
为什么?
#import <Foundation/Foundation.h>
main() {
NSURL *url = [NSURL URLWithString:@"http://www.google.com/"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:60];
NSURLResponse *response;
NSError *error;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"Data were download below:\n%@", [[NSString alloc] initWithData:data encoding: NSASCIIStringEncoding]);
}
run the executable ->
Data were download below:
[null]
Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过分配请求和错误?
NSURLResponse *response = [[NSURLResponce alloc] init];
NSError *error = [[NSError alloc] init];
Have you tried allocating the request and error?
NSURLResponse *response = [[NSURLResponce alloc] init];
NSError *error = [[NSError alloc] init];