【问题标题】:Simple http request in gnustep's objective c not workinggnustep目标c中的简单http请求不起作用
【发布时间】:2011-11-30 21:02:27
【问题描述】:
#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]); 
}

运行可执行文件-> 数据下载如下: [空]

为什么?

【问题讨论】:

  • 显而易见的问题:error 说什么?
  • if (error != nil) [error userInfo] -> 分段错误
  • 现在这很有趣。即使是普通的NSLog(@"%@", error) 也会这样吗?
  • 是的,也导致了段错误。
  • 但是,tcpdump 正确显示了 http req/resp。

标签: objective-c http gnustep


【解决方案1】:

您是否尝试过分配请求和错误?

NSURLResponse *response = [[NSURLResponce alloc] init];

NSError *error = [[NSError alloc] init];

【讨论】:

    猜你喜欢
    • 2020-07-11
    • 1970-01-01
    • 2014-07-04
    • 1970-01-01
    • 2018-03-06
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多