Iphone with Cocoa XML-RPC Framework

Source: Internet
Author: User

Recently, I had to deal with rpc_xml for a project. I had been trying to parse xml in many ways. It is really troublesome to use soap to send data to the server in xml format, it takes a long time to add "\ n" To A boby. Fortunately there is a box Cocoa XML-RPC Framework, saving me a lot of trouble, but encountered a lot of problems in the use of the Framework, so that I am very tangle, find the relevant configuration on the internet is less pitiful, after a day, I finally knew how to use it.

 

1, download The Cocoa XML-RPC Framework, is:

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. It is a little troublesome to introduce CocoaXMl into your project. 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 using Cocoa XML-RPC

// Create a url

NSURL * URL = [NSURL URLWithString: @ "localhost: 8080"];

// Create a request, which is equivalent to the NSURLRequest In the sdk

 

XMLRPCRequest * request = [[XMLRPCRequest alloc] initWithURL: URL];

// Create a connection server class and NSURLConnection In the sdk. It encapsulates this class and you can check its source code.

XMLRPCConnectionManager * manager = [XMLRPCConnectionManager sharedManager];

// Encapsulate the parameters you want to pass into an array

NSArray * uAndP = [NSArray arrayWithObjects: firstName, lastName, nil];

// Set UserAgent

[Request setUserAgent: @ "The Incutio XML-RPC PHP Library"];

// Set the method to be called after you transmit data to the server

[Request setMethod: @ "IXR. login" withParameters: uAndP];

// Print out the data you want to send to the server. At this time, it is automatically encapsulated into an xml format.

NSLog (@ "Request body: % @", [request body]);

// Send the request. There is a proxy. You need to implement XMLRPCConnectionDelegate

[Manager spawnConnectionWithXMLRPCRequest: request delegate: self];

 

[Request release];

The following describes how to implement the proxy class: the proxy class can obtain various information about the server.

// Error message

-(Void) request :( XMLRPCRequest *) request didFailWithError :( id) error {

NSLog (@ "% @", error );

}

 

// Get the data returned by the server

-(Void) request :( XMLRPCRequest *) request didReceiveResponse :( XMLRPCResponse *) response {

// Print it and check it out.

NSLog (@ "% @", [response body]);

}

-(BOOL) request :( XMLRPCRequest *) request canAuthenticateAgainstProtectionSpace :( NSURLProtectionSpace *) protectionSpace {

Return YES;

}

 

-(Void) request :( XMLRPCRequest *) request didCancelAuthenticationChallenge :( NSURLAuthenticationChallenge *) challenge {

}

-(Void) request :( XMLRPCRequest *) request didReceiveAuthenticationChallenge :( NSURLAuthenticationChallenge *) challenge {

}

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.