Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

shweta13

macrumors member
Original poster
Aug 7, 2008
38
0
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

macrumors regular
Mar 24, 2008
108
1
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

macrumors member
Original poster
Aug 7, 2008
38
0
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:mad:"http://dev.transclick.com/translation/xmlrpc2me?"];
NSMutableURLRequest* pRequest = [NSMutableURLRequest requestWithURL:pUrl cachePolicy:NSURLRequestUseProtocolCachePolicytimeoutInterval:60.0];


NSString* pStr = [[NSString alloc] initWithString:mad:"<?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:mad:"text/xml; charset=utf-8" forHTTPHeaderField:mad:"Content-Type"];
[pRequest setValue:[NSString stringWithFormat:mad:"%d", [pBody length]] forHTTPHeaderField:mad:"Content-Length"];
[pRequest setHTTPMethod:mad:"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

macrumors newbie
Nov 12, 2008
9
0
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

macrumors regular
Mar 24, 2008
108
1
Here is a snippet from my app. It doesnt send XML, but it does send content in the post body.

Code:
  // 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];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.