iPhone应用程序和服务器之间的图像传输

问题描述:

解析方法很多,例如NSXML,JSON等.我对这么多方法感到困惑.因此,请帮助我选择其中的一个.如果必须从iPhone应用程序中检索图像并将其上传到远程服务器,哪种方法将是最好的解析方法?

There are many kinds of parsing methods like NSXML , JSON etc etc. I am confused with so many methods. So please help me out to choose out of them. Which will be the best parsing method to be followed if images have to be retrieved from and uploaded to a remote server in an iPhone application??

  1. 使用XML检索图像列表.(将其存储在服务器上或从Web服务获取)
  2. 使用NSXmlParser解析并获取图像URL.
  3. 使用它来获取图像.[NSData dataWithContentsOfURL:<#(NSURL *)url#>]或者使用以下内容.

  1. Use XML to retrive list of images.(Store it on server or get it from web service)
  2. Use NSXmlParser to parse and get image URL.
  3. Use this for getting image. [NSData dataWithContentsOfURL:<#(NSURL *)url#>] OR Use following.

 NSURL *url = [NSURL URLWithString:[fileUrl
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];

webData = [[NSMutableData alloc] init];

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest    
delegate:self startImmediately:YES];

或SOAP代码

    NSURL *url = [NSURL URLWithString:@"<URL>"];
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
    theRequest = [NSMutableURLRequest requestWithURL:url];
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content- Type"];
    [theRequest addValue: @"<ADD Value Here>" forHTTPHeaderField:@"SOAPAction"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
    NSURLConnection theConnection = [[NSURLConnection alloc] initWithRequest:theRequest 
    delegate:self startImmediately:YES];

在上面,如果您将文件的URL作为请求传递给某个Web服务,并且它返回绑定了文件数据的XML,然后通过NSXmlParser对其进行解析,并在以下方法中将数据写入文件中.

In above if you are passing URL of file to some web service as request and it returns XML with with file data bound in it then parse it through NSXmlParser and in following method write data in file.

-(void)解析器:(NSXMLParser *)解析器didEndElement:(NSString *)elementNamenamespaceURI:(NSString *)namespaceURIqualifiedName:(NSString *)qName {

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{

如果需要任何其他帮助,请在此处写.

write here if you need any further assistance.