Can we make XML-RPC calls from iPhone?

Discussion in 'iOS Programming' started by shweta13, Nov 10, 2008.

  1. macrumors member

    Joined:
    Aug 7, 2008
    #1
    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
     
  2. macrumors regular

    Joined:
    Mar 24, 2008
    #2
    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?
     
  3. thread starter macrumors member

    Joined:
    Aug 7, 2008
    #3
    How exactly should I POST XML ...is it in the form of HTTPBody?

    The following is my problem:-



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

    Joined:
    Nov 12, 2008
  5. thread starter macrumors member

    Joined:
    Aug 7, 2008
    #5
    Thnks for ur help

    Unfortunately, NSXMLNode and NSXMLDocument are not supported on iPhone device :(
     
  6. macrumors newbie

    Joined:
    Nov 12, 2008
    #6
    it works well in my iPhone simulator..

    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
     
  7. macrumors regular

    Joined:
    Mar 24, 2008
    #7
    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];
     

Share This Page