views:

42

answers:

1

hi all

i am developing one app which will login to vonage website and do some functions like call froward etc . For that purpose first i am trying to login to vonage website  

i did these steps

1) Found the login url of vonage

https://secure.vonage.com/vonage-web/public/login.htm

2) used livehttpheader addon to capture outgoing post request data when i clicked sigin

the data i found is

username=myusername&password=mypassword&redirectingURL=%2Fwebaccount%2Fdashboard%2Fchoose.htm&frontDoorLogin=&goToSelection=callforwarding&loginsubmit=Sign+In

after i got my data i started coding in xcode , i dont know what is best way to do it but i searched for sometime then i tried like this

-(IBAction) buttonpressed { 

    NSURL *url = [NSURL URLWithString:@"https://secure.vonage.com/vonage-web/public/login.htm"];

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setValue:@"myuser" forKey:@"username"];
    [request setValue:@"mypass" forKey:@"password"];
    [request setValue:@"/webaccount/dashboard/choose.htm" forKey:@"redirectingURL"];
    [request setValue:@"" forKey:@"frontDoorLogin"];
    [request setValue:@"callforwarding" forKey:@"goToSelection"];
    [request setValue:@"Sign+In" forKey:@"loginsubmit"];
    [request setDelegate:self];
    [request startAsynchronous];



}

- (void)requestFinished:(ASIFormDataRequest *)request
{
    // Use when fetching text data
    NSString *responseString = [request responseString];

    UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"Hmm" message:@"http works" delegate:self cancelButtonTitle:@"okay" otherButtonTitles:nil];

    [alert show];
    [alert release];
    NSLog(@"Output = %@",responseString);

}

- (void)requestFailed:(ASIFormDataRequest *)request
{
    NSError *error = [request error];
    UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"fail" message:@"http fails" delegate:self cancelButtonTitle:@"okay" otherButtonTitles:nil];

    [alert show];
    [alert release];
}

but when i ran app in my simulator it crashed .

am i doing correct way in posting data ? and is there any other way to do this ?

can any one help me in this issue

i am using asihttprequest library

thanks in advance

regards

Edit : My blind mistake i types setvalue instead of setpostvalue ,this will solve this issue :)

A: 

look at the section titled Sending a form POST with ASIFormDataRequest

// using post value 
[request setPostValue:@"myuser" forKey:@"first_name"];

also I usually do my alerts with an autorelease, not sure if that is your problem but you might want to try that changes also

    UIAlertView *alert= [[[UIAlertView alloc] initWithTitle:@"Hmm" message:@"http works" 
         delegate:self cancelButtonTitle:@"okay" otherButtonTitles:nil] autorelease];

   [alert show];

UIAlertView Delegate Code

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:
                                                     (NSInteger)buttonIndex {
       // do your thing
    }
Aaron Saunders
thanks for reply sir , i did what is stated in that tutorial , and i removed alert views but still same error . my main question is this the way we use to post data in iphone (sorry i am new iphone coding )
appleDE
i suspect the problem is you are not handling the cert that is coming from the https website
Aaron Saunders
can u please tell me how to handle https (ssl or xx ) certificates ?
appleDE
@appleDE here is some code I used when I wrote a phoneGap plugin http://blog.clearlyinnovative.com/post/1012434483/phonegap-and-iphone-development
Aaron Saunders
thanks for reply sir , i fixed my problem ,i am a blind noob ,i didnt used setPostvalu i used setvalue i thought i used but idk ,anyway thanks for u r help sir :)
appleDE
@appleDE you should update the question with the correct answer to help others
Aaron Saunders
done sir :) , thanks again :)
appleDE