How to capture the response from a server

  • 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
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today