• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to capture the response from a server
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to capture the response from a server


  • Subject: How to capture the response from a server
  • From: dee gee <email@hidden>
  • Date: Tue, 31 Oct 2006 10:50:45 +0000 (GMT)

  Hi All

 I am a new bee.
 I am trying to create a login page.
 Here I accept the userid and password and when the user hits submit button the method loginUser would be executed.

 I am trying to connect to a JavaServer in the Backend (running on a Windows m/c).
 I am connecting to the server but my application is hanging at the following line:
   responseData = [[NSMutableData alloc] init];
  How do I capture the response from the server?
  I have pasted my whole code below. The server’s response would be “Valid User” or “Invalid User”.

 I have now hard coded the URL now as I don’t know how to send the inputs individually.  (I can use POST but how to pass the parameters in case I have more than 4 and secure ones like the userId and password?)
  Can someone please help me with this?

 One more thing is that I couldn't use @try and @catch methods, are there any pre-requisites for this?

 Thank you,
 Dee
 PS: I have got all the code from the net. (Mostly developer.apple.com)


 @interface Login : NSObject
 {
     IBOutlet NSTextField *password;
     IBOutlet NSTextField *userId;

     NSMutableData *responseData ;
 }

 - (IBAction)loginUser:(id)sender;

 @end

 @implementation Login

 - (IBAction)loginUser:(id)sender
 {
     NSString *usrId;
     NSString *pwd;



     NSLog (@" local variables created");

     usrId = [userId stringValue];
     pwd = [password stringValue];
     //pwd = [self valueForKey:@"password"];
     NSLog (@"Data copied to local variables");

     NSLog (@"UserID = %@, Password = %@", usrId, pwd);

     //@try {

     NSURL *myURL = [NSURL URLWithString:@"http://172.19.23.74:8080/DemoApp/DemoServ?userId=dee&password=bee";];

     NSLog (@"URL written");

     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL]; // cachePolicy:NSURLRequestUserProtocolCachePolicy timeoutInterval:60.0];

     NSLog (@"request loaded");

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

     NSLog (@"connection established");

     if (conn) {
         NSLog (@"in the if loop");

         responseData = [[NSMutableData alloc] init]; // is this correct since the application hangs here. Here I am trying to capture the server’s response.

         NSLog (@"response = %@", [responseData mutableBytes]);
         }

     /*}

     @catch(NSException e){
         NSLog (@"there has been an error %@", e);

     }@finally{
         NSLog (@"the program is complete");
     }*/

     NSLog (@"Finished");
 }


---------------------------------
 Find out what India is talking about on  - Yahoo! Answers India
 Send FREE SMS to your friend's mobile from Yahoo! Messenger Version 8. Get it NOW

---------------------------------
 Find out what India is talking about on  - Yahoo! Answers India
 Send FREE SMS to your friend's mobile from Yahoo! Messenger Version 8. Get it NOW
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: NSImages rendered at runtime and resolution independent UI...
  • Next by Date: Re: Core Data Application Problem
  • Previous by thread: Re: Core Data Application Problem
  • Next by thread: Creator Code for Packages
  • Index(es):
    • Date
    • Thread