2012-03-15 95 views
1

我试图调用Web服务,但unfortunateley我的电话不被记录,我不知道它为什么这样做?无法调用webservice的

这里是我使用的代码,也许我我失去了一些东西:

NSURL *URL = [NSURL URLWithString:@"http://www.google.com"]; 
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:URL]; 

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

所有我需要做的就是能够加载一个网页,而无需将其加载到Safari浏览器也没有在网页视图

的感谢!

+0

[目标C,打开网站而无需在Safari中打开它(用于服务器调用目的)]的可能重复](http://stackoverflow.com/questions/9726389/objective-c-opening-a-website-without-开它,在野生动物园换服务器呼叫PU) – hotpaw2 2012-03-15 23:06:01

回答

0

结账this tutorial关于如何与iOS中的web服务连接。这并不像建立连接那么简单。

0
NSURL *url = [NSURL URLWithString:webService]; 
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0]; 
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];  
    if(theConnection) { 
     //webData = [[NSMutableData data] retain];  
    }else { 
     NSLog(@"The Connection is NULL"); 
    } 
} 

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 
    webData = [[NSMutableData data] retain]; 
} 

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 
    [webData appendData:data]; 
} 

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { 
}