How can I connect iPhone and web service and get XML data?

前端 未结 4 1365
南笙
南笙 2020-12-04 05:58

I know how to connect to web server using an iPhone but now I have to connect the iPhone to a web service. I don\'t know how to do it and there is no demo or class available

相关标签:
4条回答
  • 2020-12-04 06:26

    You might find this tutorial, called Intro to SOAP Web Services useful. He shows how to package a request, send it to a web service, and read the response.

    If you need some help with XML parsing, there is the TouchXML library which will give you a nice xml "document" to work with. Just be cautious of memory usage.

    If you have to parse large XML message this tutorial about libxml and xmlreader in Cocoa will show you how to parse XML with the lower-level event-style parsers.

    0 讨论(0)
  • 2020-12-04 06:29

    I've created an open source application for iPhone OS 3.0 that shows how to use REST & SOAP services in iPhone application, using XML (using 8 different iPhone libraries), SOAP, JSON (using SBJSON and TouchJSON), YAML, Protocol Buffers (Google serialization format) and even CSV from a PHP sample app (included in the project).

    http://github.com/akosma/iPhoneWebServicesClient

    The project is modular enough to support many other formats and libraries in the future.

    The following presentation in SlideShare shows my findings in terms of performance, ease of implementation and payload characteristics:

    http://www.slideshare.net/akosma/web-services-3439269

    0 讨论(0)
  • 2020-12-04 06:31

    You can use these 2 lines which return the response of your HTTP request. You don't need any configuration. This code is usefull if you try to access a PHP scritp for example. After you just have to parse your result.

    NSURL *URL=[[NSURL alloc] initWithString:stringForURL];
    NSString *results = [[NSString alloc] initWithContentsOfURL :URL];
    
    0 讨论(0)
  • 2020-12-04 06:34

    In my opinion, you have two options :

    • Use a third party library. You can try wsdl2objc. It didn't work for me, but it is under active development so it improves every day.
    • Use a raw HTTP connection and handle every request/response. This is the way I followed. It is hard, so I'd also like to know a better approach.
    0 讨论(0)
提交回复
热议问题