Use Cocoa xml rpc Framework in iPhone Development

Source: Internet
Author: User

IPhone DevelopmentUsed inCocoa XMLRPC Framework is the content to be introduced in this article _XmlI have always wanted to parse xml. There are many methods. It is really troublesome to use soap to send data to the server in xml format. It is quite time-consuming to add "\ n" to boby. Fortunately, there is a boxCocoa XML-RPC Framework saves me a lot of trouble, but I encountered a lot of problems when using the Framework, which made me very entangled. I found few relevant configurations on the internet, after a day, I finally knew how to use it.

1. Download The Cocoa XML-RPC Framework:

 
 
  1. http://github.com/eczarny/xmlrpc 

2. decompress the package. You can see Tools, UnitTests, build, and some class files.

The Tools contains two folders: Test Client and Test Server. If you do not have an accessible Server, add these two files for local testing, the premise is that you must install the Server locally and then run the Test Server.

3. About how to introduce CocoaXMl into your project, this is a little troublesome. I have been trying to introduce the framework in the build, but there are many errors. In fact, there is a simple solution, first, open xmlRPc. xcodeProj file. After the project is enabled, copy all the files under the project Classes to your project. When you run your project, you will find an error, but it doesn't matter, directly Delete the error and run it. Now you can see how to use this framework. It is very easy to use.

4. Use Cocoa XML-RPC

 
 
  1. // Create a url
  2. NSURL * URL = [NSURL URLWithString: @ "localhost: 8080"];
  3. // Create a request, which is equivalent to the NSURLRequest In the sdk
  4. XMLRPCRequest * request = [[XMLRPCRequest alloc] initWithURL: URL];
  5. // Create a connection server class and NSURLConnection In the sdk. It encapsulates this class and you can check its source code.
  6. XMLRPCConnectionManager * manager = [XMLRPCConnectionManager sharedManager];
  7. // Encapsulate the parameters you want to pass into an array
  8. NSArray * uAndP = [NSArray arrayWithObjects: firstName, lastName, nil];
  9. // Set UserAgent
  10. [Request setUserAgent: @ "The Incutio XML-RPC PHP Library"];
  11. // Set the method to be called after you transmit data to the server
  12. [Request setMethod: @ "IXR. login" withParameters: uAndP];
  13. // Print out the data you want to send to the server. At this time, it is automatically encapsulated into an xml format.
  14. NSLog (@ "Request body: % @", [request body]);
  15. // Send the request. There is a proxy. You need to implement XMLRPCConnectionDelegate
  16. [Manager spawnConnectionWithXMLRPCRequest: request delegate: self];
  17. [Request release];

The following describes how to implement the proxy class:

Various server information can be obtained in the proxy class

 
 
  1. // Error message
  2.  
  3. -(Void) request :( XMLRPCRequest *) request didFailWithError :( id) error {
  4. NSLog (@ "% @", error );
  5. }
  6. // Get the data returned by the server
  7. -(Void) request :( XMLRPCRequest *) request didReceiveResponse :( XMLRPCResponse *) response {
  8. // Print it and check it out.
  9. NSLog (@ "% @", [response body]);
  10. }
  11. -(BOOL) request :( XMLRPCRequest *) request canAuthenticateAgainstProtectionSpace :( NSURLProtectionSpace *) protectionSpace {
  12. Return YES;
  13. }
  14. -(Void) request :( XMLRPCRequest *) request didCancelAuthenticationChallenge :( NSURLAuthenticationChallenge *) challenge {
  15. }
  16. -(Void) request :( XMLRPCRequest *) request didReceiveAuthenticationChallenge :( NSURLAuthenticationChallenge *) challenge {
  17. }

Summary: DetailsIPhone DevelopmentUsed inCocoa XMLThe content of the RPC Framework has been introduced. I hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.