PDA

View Full Version : Can we make XML-RPC calls from iPhone?




shweta13
Nov 10, 2008, 06:37 AM
Hi all,

Can we make XML-RPC protocols to any server on net?
From the results that I got from my search, XML-RPC calls can be done using
AppleScript,but not on iPhone.

Anyone has any ideas why.....

Thanks



SqueegyX
Nov 10, 2008, 01:42 PM
I'm not sure if a library exists to help with this or not, but you can just POST some XML to an address right? What support do you need besides basic HTTP messages?

shweta13
Nov 14, 2008, 01:56 AM
I'm not sure if a library exists to help with this or not, but you can just POST some XML to an address right? What support do you need besides basic HTTP messages?

How exactly should I POST XML ...is it in the form of HTTPBody?

The following is my problem:-



NSURL *pUrl = [NSURL URLWithString:@"http://dev.transclick.com/translation/xmlrpc2me?"];
NSMutableURLRequest* pRequest = [NSMutableURLRequest requestWithURL:pUrl cachePolicy:NSURLRequestUseProtocolCachePolicytimeoutInterval:60.0];


NSString* pStr = [[NSString alloc] initWithString:@"<?xml version='1.0' encoding='UTF-8'?><methodCall><methodName>authentication.signin</methodName><params><param><value><string>username</string></value></param><param><value><string>password</string></value></param></params></methodCall>"];
NSData* pBody = [pStr dataUsingEncoding:NSStringEncodingConversionAllowLossy];

[pRequest setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[pRequest setValue:[NSString stringWithFormat:@"%d", [pBody length]] forHTTPHeaderField:@"Content-Length"];
[pRequest setHTTPMethod:@"POST"];
[pRequest setHTTPBody:pBody];

m_pUrlConnection = [[NSURLConnection alloc] initWithRequest:pRequest delegate:self];



When I handle the delegates of NSURLConnection, I get response as "Invalid request"
Can anyone help?

david.david
Nov 14, 2008, 05:21 AM
look at
http://davidiphone.blogspot.com/

shweta13
Nov 14, 2008, 07:56 AM
look at
http://davidiphone.blogspot.com/

Thnks for ur help

Unfortunately, NSXMLNode and NSXMLDocument are not supported on iPhone device :(

david.david
Nov 15, 2008, 12:02 AM
it works well in my iPhone simulator..

NSXMLNode and NSXMLDocument are not supported on iPhone device

means it works in simulator and not work with actual device ?

if NSXMLNode and NSXMLDocument are not working, then initialize the NSString with desired format like 3rd post and convert NSString to NSData


//////////////
I am using
iphone_sdk_for_iphone_os_2.1__final

SqueegyX
Nov 15, 2008, 11:24 AM
Here is a snippet from my app. It doesnt send XML, but it does send content in the post body.

// Create the request
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://www.shacknews.com/extras/post_laryn_iphone.x"]];

// Set request body and HTTP method
NSString *usernameString = [LatestChattyAppDelegate urlEscape:[[NSUserDefaults standardUserDefaults] stringForKey:@"username_preference"]];
NSString *passwordString = [LatestChattyAppDelegate urlEscape:[[NSUserDefaults standardUserDefaults] stringForKey:@"password_preference"]];
NSString *bodyString = [LatestChattyAppDelegate urlEscape:postContent.text];
NSString *parentId = [NSString stringWithFormat:@"%d", parentPost.postId];
if ([parentId isEqualToString:@"0"]) parentId = @"";


NSString *postBody = [NSString stringWithFormat:@"body=%@&iuser=%@&ipass=%@&parent=%@&group=%d", bodyString, usernameString, passwordString, parentId, storyId];
[request setHTTPBody:[postBody dataUsingEncoding: NSASCIIStringEncoding]];
[request setHTTPMethod:@"POST"];

// Send the request
NSHTTPURLResponse *response;
NSString *responseBody = [[NSString alloc] initWithData:[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil]
encoding:NSASCIIStringEncoding];