0

I am new to iPhone programming, and this is the first time parsing XML file. I have added the url and also hardcoded the XML file into the string, however I am not getting the correct response from the server.

Here is my code:

NSString *post = @"<?xml version=\"1.0\"encoding=\"UTF-8\"?<request><call>GetNewChapters</call><udid>1000000000000000000000000000000000000000</udid><book_id>1</book_id><updatetoken>B20100125054802</updatetoken></request>";

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSURL *url=[NSURL URLWithString:@"https://www.paisible.com/babelle_api"];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];    
[request setHTTPBody:postData];



NSString *myStr = [[NSString alloc] initWithData:postData encoding:NSUTF8StringEncoding];
NSLog(@"String Value :%@",myStr);


NSLog(@"theRequest: %@", request);
NSURL *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(theConnection)
{
    webData = [[NSMutableData data] retain];
}
else
{
    NSLog(@"theConnection is NULL");
}

Where as webdata is NSMutable data. Please let me know what errors I have made in my parsing code.

7
  • Whoosa! calm down we will try get this fixed. No need to scream. Commented Feb 23, 2011 at 6:27
  • Oops! Your caps lock key appears to be broken. Commented Feb 23, 2011 at 6:29
  • 1
    Please clarify your last two sentences - preferably without full caps. Commented Feb 23, 2011 at 6:31
  • i can also provide the xml structure <?xml version="1.0" encoding="UTF-8"?> <request> <call>GetNewChapters</call> <udid>1000000000000000000000000000000000000000</udid> <book_id>1</book_id> <updatetoken>B20100125054802</updatetoken> </request> plz let me know whats wrong with the code and also check for the url Commented Feb 23, 2011 at 6:40
  • What is the response you are getting? I think you havent pasted/written the delegate methods for getting the response. Commented Feb 23, 2011 at 7:03

1 Answer 1

1

Try to replace

NSURL *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

with the following:

NSURLResponse *resp;
NSError *error;
NSMutableData *webData = [NSURLConnection sendSynchronousRequest:request returningResponse:&resp error:&error]; 

Than, check what "webData" contains.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the information, but Mike i have implemented what you have said,however it didn't work, showing the same response as previous and also one warning (Incompatible Ojective-C types assigning struct NSDATA expected struct NSMutableData) also MIKE please let me know wheather is there any problem with the url.
try to allocate the request like this: NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
i have find the solution, and its working and getting response from the server when we start to read xml i have written @"xml = and the rest of the string,thanks for the information and help.
Hello @kashif Please share your solution as an Answer so it may help to other also, i have also same problem. so please share.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.