ASIHTTPRequest issue
I am trying to develop an app which will use this Cytamobile-Vodafone webservice to login.
I have used HTTP Live Header add-on with Mozilla to get this one: %3D&HeaderLogin1%24CybeeUserName1%24txtUserName=mavris&HeaderLogin1%24CybeePassword1%24txtPassword=XXXXX&HeaderLogin1%24ibtnLogin.x=20&HeaderLogin1%24ibtnLogin.y=4 HTTP/1.1 302 Found
First I noticed that ibtnLogin.x and ibtnLogin.y have not the same value each time I am trying to login.
Second I wrote this code:
-(IBAction) buttonpressed {
NSURL *url = [NSURL URLWithString:@"https://www.cytamobile-vodafone.com/miPortal/HeaderLoginBar.aspx"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"xxxxxx" forKey:@"txtUserName"];
[request setPostValue:@"xxxxxx" forKey:@"txtPassword"];
[request setPostValue:@"31" forKey:@"ibtnLogin.x"];
[request setPostValue:@"7" forKey:@"开发者_运维知识库ibtnLogin.y"];
[request setDelegate:self];
[request startAsynchronous];
[self requestFinished:request];
}
- (void)requestFinished:(ASIFormDataRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseStatusMessage];
NSLog(@"Output = %@",responseString);
}
and I get:
"Output = HTTP/1.1 200 OK" instead of 302 Found or any other error
What am I doing wrong here?
At least one of your problems is that your code shouldn't be calling [self requestFinished:request];
after [request startAsynchronous];
The startAsynchronous method starts an asynchronous request, so it will execute the request in a different thread and let you know when it's done.
When the request is complete, ASIHTTPRequest code will call the requestFinished:
method. It the request fails, it will instead call requestFailed:
. You don't call these methods, the ASIHTTPRequest code will. Check out the ASIHTTPRequest docs.
This the standard delegate pattern you'll see a lot in Objective-C (here is one question of many about delegation here on SO).
精彩评论