我有這個RESTFUL API調用。我嘗試連接到Web服務。響應成功接收,但是當我註銷數據接收時,它沒有。請幫幫我。我的休息信息是否錯誤?IOS如何使用RESTFUL API從Web服務檢索數據
這裏是我的編碼:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
feeds = [[NSMutableArray alloc] init];
NSString *restMessage = [NSString stringWithFormat:@"https://deepsightapi.symantec.com/v1/domains/www.google.com/"];
NSURL *url = [NSURL URLWithString:restMessage];
NSURLRequest *theRequest = [NSURLRequest requestWithURL:url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
//[connection start];
if(connection)
{
_webResponseData = [NSMutableData data] ;
}
else
{
NSLog(@"Connection is NULL");
}
}
- (void)connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"Response recieved");
[self.webResponseData setLength:0];
}
- (void)connection:(NSURLConnection*) connection didReceiveData:(NSData *)data
{
NSLog(@"Data recieved");
[self.webResponseData appendData:data];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"Received %lu Bytes", (unsigned long)[_webResponseData length]);
NSString *theXML = [[NSString alloc] initWithBytes:
[_webResponseData mutableBytes] length:[_webResponseData length] encoding:NSUTF8StringEncoding];
NSLog(@"hello %@",theXML);
//now parsing the xml
NSData *myData = [theXML dataUsingEncoding:NSUTF8StringEncoding];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:myData];
//setting delegate of XML parser to self
xmlParser.delegate = self;
// Run the parser
@try{
BOOL parsingResult = [xmlParser parse];
NSLog(@"parsing result = %hhd",parsingResult);
}
@catch (NSException* exception)
{
UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"Server Error" message:[exception reason] delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
return;
}
}
你可以發佈你的NSLogs嗎? – Duc