0

How do I write objective-C code to click this HTML submit button in iOS?

<input type="password" class="lp_input" size="13" name="password" autocomplete="off">
<input type="text" class="lp_input" size="13" name="username" value="" autocomplete="off">
<input name="login" id="submitform" type="submit" class="o" value="Logon">


I've already created a request object, but don't know how to use it to submit the above.

NSURL *url = [NSURL URLWithString:@"https://connect.website.com"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

[request setHTTPMethod:@"POST"];

[request setValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
[request setValue:self.userName forHTTPHeaderField:@"username"];
[request setValue:self.Password forHTTPHeaderField:@"password"];
//HOW DO I SUBMIT THIS?

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

[connection start];

if (connection) {
    mutData = [NSMutableData data];
}
4

2 回答 2

1

尝试这个

如果您的页面http://test.com/form.php具有以下形式:

<form name="login" method="POST" action="action.php">
    <input name="username"><br />
    <input name="password"><br>
    <input type="submit">
</form>

您可以使用此代码来执行此表单。

NSURL *url = [NSURL URLWithString:@"http://test.com/action.php];
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setPostValue:@"Admin" forKey:@"username"];
[request setPostValue:@"1234" forKey:@"password"];
[request startSynchronous];

它真的会帮助你。

于 2013-09-09T04:24:28.377 回答
1

把你在做的事情想象成一个浏览器。当用户在浏览器中提交表单时,浏览器会将表单数据发布到表单标签的action属性中的url。因此,您所要做的就是向服务器发出与浏览器相同的请求以提交表单。忘记尝试伪装成用户,伪装成浏览器,直接将表单数据发布到服务器。

于 2013-09-09T04:27:32.803 回答