Iphone Webservice n sqlite
我有web服务,我想在iPhone的SQLite中保存这些数据,还想检索这些数据。Web服务包括14个参数,还包括图像URL。Web服务是.NET中的SOAPIphone Webservice n sqlite,iphone,sqlite,Iphone,Sqlite,我有web服务,我想在iPhone的SQLite中保存这些数据,还想检索这些数据。Web服务包括14个参数,还包括图像URL。Web服务是.NET中的SOAP 请帮助我,并提供完整的代码如何做到这一点。Web服务可能采用Java、PHP、.NET等语言。。。但是您必须使用相同的过程来发出请求。 在这里,我给出了发出请求并从webservices获取响应的示例代码 -(void)performRequest{ NSAutoreleasePool *pool = [[NSAutorelea
请帮助我,并提供完整的代码如何做到这一点。Web服务可能采用Java、PHP、.NET等语言。。。但是您必须使用相同的过程来发出请求。 在这里,我给出了发出请求并从webservices获取响应的示例代码
-(void)performRequest{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"url"]];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[request addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue: soapAction forHTTPHeaderField:@"SOAPAction"];
[request addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if( theConnection )
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"theConnection is NULL");
}
[pool release];
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
[webData setLength: 0];
self.resultArray = [[NSMutableArray alloc] init];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(@"ERROR with theConenction");
NSDictionary *errorDic = [NSDictionary dictionaryWithObject:error forKey:@"error"];
[self.resultArray addObject:errorDic];
[connection release];
[webData setLength:0];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@", theXML);
[theXML release];
if([webData length] > 0){
parser = [[NSXMLParser alloc] initWithData:webData];
[parser setDelegate:self];
[parser parse];
}
}
在本例中,“webData”(NSData)具有响应数据。请求应为XML格式,响应数据也应为XML格式。使用NSXMLParser可以解析数据。
有一些委托方法。您必须使用以下指定的方法
1. - (void)parserDidStartDocument:(NSXMLParser *)parser
2. - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
3. - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
4. - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
5. - (void)parserDidEndDocument:(NSXMLParser *)parser
6. - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
1. - (void)parserdistartdocument:(NSXMLParser*)解析器
2. - (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName属性:(NSDictionary*)attributeDict
3. - (void)解析器:(NSXMLParser*)解析器查找字符:(NSString*)字符串
4. - (void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qName
5. - (void)parserDidEndDocument:(NSXMLParser*)解析器
6. - (void)解析器:(NSXMLParser*)解析器解析错误发生:(NSError*)解析错误
在第二个委托方法中,您将获得元素名(xml标记名)。
在第三个委托方法中,您将获得元素名称的值
我希望,这会对你有所帮助。你可能应该从一个不太接近“为我编写整个应用程序”的问题开始。兄弟,我对iphone的开发还不熟悉,这就是我问这个问题的原因。如果你帮不上忙,那就不要这样批评。祝你好运汉克斯·维杰希望你将来也能帮助我。