title: How to retrieve a response from server for the request sent?
body: <p>I am developing an application that connects to a remote web server and exchanges data with the web server frequently. First screen of my application provides login screen that authenticates user. </p>
  
  <p>I am able to authenticate user on the web server by sending a request to the server but unable to get response from the server to display success alert to the user on the iphone. In clear, I am not getting any response.</p>
  
  <p>The server I'm using is developed in Java. </p>
  
  <p>I am using the following to send the request to server.</p>
  
  <pre><code>NSString *post = @"username=";
  
  post = [post stringByAppendingString:username];
  post = [post stringByAppendingString:@"&amp;password="];
  post = [post stringByAppendingString:password];
  
  NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
  
  NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
  
  NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
  [request setURL:[NSURL URLWithString:@"http://example.com/login.action?"]];
  [request setHTTPMethod:@"POST"];
  [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
  [request setHTTPBody:postData];
  NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
  </code></pre>
  
  <p>And, </p>
  
  <pre><code>- (void)connectionNSURLConnection *)connection didReceiveDataNSData *)data
  {
  [receivedData appendData:data];
  NSString *ReturnStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  NSLog(@"In \"didReceiveData()\" : receivedData = %@",receivedData);
  NSLog(@"Return String : %@", ReturnStr);
  
  }
  </code></pre>
  
  <p>This function is never called.</p>
  
  <p>What should I do to receive response for the request I have sent?</p>
  
  <p>A brief collection of my queries:</p>
  
  <p>Example: Login screen that validates a user in Java server</p>
  
  <ol>
  <li>I am sending request that I am able to see at the console of my server application.</li>
  <li>I'm unable to get response for the request.</li>
  <li>In which format the response data must be sent?</li>
  </ol>
  
  <p>Would someone provide a clear picture of data exchange between the iPhone application and a Java servlet?</p>
  
  <h2>Update</h2>
  
  <p>I have implemented these three methods also. But no response from server. Can you guide me the process of developing LOGIN application that communicates with a JAVA server by requests and responses? I am stuck with communicating.</p>
  
  <p>Yeah, my server is receiving request from iphone. I am able to see the request that is sent to the server. </p>
  
  <p>I am not able to understand how the data exchange between iphone application and JAVA server takes place. I'm a newbie to this iphone development.</p>