NSUrl连接到某个本地网络 - 没有响应

时间:2015-07-26 07:39:31

标签: ios objective-c

我正在尝试连接到我的一些本地网络(硬件)。 所以我在iPhone设置上找到网络并连接到它。 现在,我正在尝试向该接入点发送一个简单的请求。

接入点确实收到我的请求,然后发回回复,问题是,我从未收到设备上的响应。

如果我尝试使用我的Mac上的Chrome浏览器发送请求,我会收到回复“hello world”,但不会在设备上。

我尝试过同步和取消同步请求,其中没有给我什么。他们虽然发送了请求。我错过了什么?

同步

  NSURLRequest * urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.x.x/data:moredata"]];
    NSURLResponse * response = nil;
    NSError * error = nil;
    NSData * tdata = [NSURLConnection sendSynchronousRequest:urlRequest
                                          returningResponse:&response
                                                      error:&error];

    NSLog(@"-%@",tdata);

和async ,没有调用代理:(确实使用<NSURLConnectionDelegate注册了代表)

    NSMutableURLRequest *request = [ [NSMutableURLRequest alloc] init]   ;
        [request setURL:[NSURL URLWithString:@"http://192.168.x.x/data:datax"]];



         NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO  ];
        [conn scheduleInRunLoop:[NSRunLoop mainRunLoop]
                              forMode:NSDefaultRunLoopMode];
        [conn start];





- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {

    NSLog(@"+%@",response);
    _responseData = [[NSMutableData alloc] init];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
     NSLog(@"-%@",data);
    [_responseData appendData:data];
}

- (NSCachedURLResponse *)connection:(NSURLConnection *)connection
                  willCacheResponse:(NSCachedURLResponse*)cachedResponse {
     return nil;
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
     NSLog(@"DO");

}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
     NSLog(@"FAILEDERR");

}

0 个答案:

没有答案
相关问题