V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
wohenyingyu01
V2EX  ›  问与答

用 oc 发 http get 无任何反应,求解

  •  
  •   wohenyingyu01 · 2016-03-03 11:38:55 +08:00 · 1326 次点击
    这是一个创建于 2947 天前的主题,其中的信息可能已经有所发展或是发生改变。
    方法:

    main 函数里:


    执行后,断点不进去,结果是
    the result from ipip is (null)
    2 条回复    2016-03-03 13:19:41 +08:00
    wohenyingyu01
        1
    wohenyingyu01  
    OP
       2016-03-03 11:39:58 +08:00
    这图= =
    我把代码复制一遍好了


    +(NSString *)requestHTTPGetFromURL:(NSString *)url{
    NSString* __block result;
    NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];

    NSURL * target = [NSURL URLWithString:url];

    NSURLSessionDataTask * dataTask = [defaultSession dataTaskWithURL:target
    completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    if(error == nil)
    {
    result = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
    NSLog(@"Data = %@",result);
    }else{
    NSLog(@"The error is :%ld",[error code]);
    }

    }];

    [dataTask resume];

    return result;
    }
    xi_lin
        2
    xi_lin  
       2016-03-03 13:19:41 +08:00
    实验了一下没有问题
    Data = ["GOOGLE","GOOGLE","","","google.com"]
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2193 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:13 · PVG 00:13 · LAX 09:13 · JFK 12:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.