Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8473247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:17:50+00:00 2026-06-10T17:17:50+00:00

I am attempting to use AFNetworking with an XML-RPC based API while using GDataXML

  • 0

I am attempting to use AFNetworking with an XML-RPC based API while using GDataXML as my XML parsing and creation class.

I have successfully written some methods that output a proper XML request according to the spec of the API, I have also tested this XML request using apigee console and verified I get a correct response back every time with the apigee console and the API.

Now comes AFNetworking, I have the following code written which sometimes, but rarely works.

NSMutableURLRequest *request = [[FZAPIClient sharedClient] requestForDataServiceQueryOnTable:@"Contact" usingQueryData:@{ @"LastName" : @"Wagner" } forFields:@[ @"FirstName", @"LastName" ] withLimit:1000 forPage:0];

AFHTTPRequestOperation *operation = [[FZAPIClient sharedClient] HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {

    NSError *error = nil;
    GDataXMLDocument *opdoc = [[GDataXMLDocument alloc] initWithData:[[operation request] HTTPBody] options:0 error:&error];

    if (error) {
        NSLog(@"Error creating XML: %@", error);
    }

    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:responseObject options:0 error:nil];
    GDataXMLElement *element = [doc rootElement];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    [FZAPIErrorHandler handleError:error];
}];

[operation start];

Implementation for - (NSMutableURLRequest *)requestForDataServiceQueryOnTable:(NSString *)table usingQueryData:(NSDictionary *)queryData forFields:(NSArray *)fields withLimit:(NSInteger)limit forPage:(NSInteger)page;

- (NSMutableURLRequest *)requestForDataServiceQueryOnTable:(NSString *)table
                                            usingQueryData:(NSDictionary *)queryData
                                                 forFields:(NSArray *)fields
                                                 withLimit:(NSInteger)limit
                                                   forPage:(NSInteger)page {
    GDataXMLDocument *xmlDocument = [FZXMLGenerator requestForDataServiceQueryOnTable:table
                                                                      usingQueryData:queryData
                                                                           forFields:fields
                                                                           withLimit:limit
                                                                             forPage:page];
    NSMutableURLRequest *request = [self requestWithMethod:@"POST" path:@"" parameters:nil];
    [request setHTTPBody:[xmlDocument XMLData]];
    [request setHTTPMethod:@"POST"];

    return request;
}

When the request works, I get an excepted response.

When the request doesn’t work (which is 99% of the time) I get the following response.

<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
   <fault>
      <value>
         <struct>
            <member>
               <name>faultCode</name>
               <value>
                  <i4>0</i4>
               </value>
            </member>
            <member>
               <name>faultString</name>
               <value>Failed to parse XML-RPC request: Premature end of file.</value>
            </member>
         </struct>
      </value>
   </fault>
</methodResponse>

This makes me suspect something is happening to the HTTPBody property, I have added logging just about everywhere I can think and see that the XML is indeed attached to the request when it is fired. It is also still accessible via the operation in the completion block.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:17:52+00:00Added an answer on June 10, 2026 at 5:17 pm

    It looks like it was as simple as setting the content type on the request.

    Updating the method to

    - (NSMutableURLRequest *)requestForDataServiceQueryOnTable:(NSString *)table
                                                usingQueryData:(NSDictionary *)queryData
                                                     forFields:(NSArray *)fields
                                                     withLimit:(NSInteger)limit
                                                       forPage:(NSInteger)page {
        GDataXMLDocument *xmlDocument = [FZXMLGenerator requestForDataServiceQueryOnTable:table
                                                                          usingQueryData:queryData
                                                                               forFields:fields
                                                                               withLimit:limit
                                                                                 forPage:page];
        NSMutableURLRequest *request = [self requestWithMethod:@"POST" path:@"" parameters:nil];
        [request setHTTPBody:[xmlDocument XMLData]];
        [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
    
        return request;
    }
    

    Solved the problem, notice the line
    [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];

    To make this global on all requests I added the line, [self setDefaultHeader:@"Content-Type" value:@"application/xml"]; to my - (id)initWithBaseURL:(NSURL *)url; implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While attempting to use the CopyFile() function I have encountered a strange error. It
I am attempting to use the following code to search a database using words
I have been attempting to use ASP.NET MVC remote validation for username login access
Attempting to use the amazon API to obtain product data and currently failing miserably.
When attempting to use pandoc to convert JSON based files (.ipynb) from iPython notebook
I'm attempting to use Google's Guava ImmutableSet class to create a set of immutable
I'm attempting to use the Github v3 API and posting JSON to update a
I'm attempting to use the Google geocoder API to enter user's location information directly
I am attempting to use a custom workflow activity to auto-increment build numbers based
I am attempting use Java Pathfinder and I have pathfinder working. import gov.nasa.jpf.jvm.Verify; user.java:2:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.