tags:

views:

27

answers:

1

i am making an app in which user's data is send to a server...the data should be in xml format.

presently i have made a string and put all into it...like following format NSString *s=[[NSString alloc]initWithFormat:@"%@%@",name.text,address.text]; (this is just an example i have made a string with full xml tags including xml version tag) and then send this through http post method.... i did it but dont know how to get response of server...please help ...any code will be helpful..... waiting for answer

+1  A: 

Take a look at NSURLConnection. You essentially create a connection, register a delegate, kick off the request and build the response as the data is passed to your delegate.

I'm working from memory here, but essentially:

  • Create an NSURLRequest for your request to your server
  • Create an NSURLConnection using the initWithRequest:(NSURLRequest *)request delegate:(id)delegate init method, passing a suitable delegate.

The request will be made, and the response will be passed back to your delegate in:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

I've not tested this, but something like:

NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"SERVER"] 

[request setHTTPMethod:@"POST"]; 
[request setHTTPBody:@"Your XML"];

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

Then in your delegate you can build the response using the data provided in the didReceiveData:(NSData *)data and didReceiveResponse:(NSURLResponse *)response methods.

dannywartnaby
very useful thanks for this exact and correct answer....i have not tried it but looking for this type thanks again.....voted and accepted...
Ranjeet Sajwan
just want to ask that should i send string that contained xml data or an attached file that has the same data ?
Ranjeet Sajwan
Just the string, so [request setHTTPBody:@"<xml><content>fhhf</content></xml>"]; should be fine.
dannywartnaby
thanks again...
Ranjeet Sajwan