本文介绍了目标C - 提交HTML表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< input type =
如何编写Objective-C代码来点击iOS中的HTML提交按钮?密码class =lp_inputsize =13name =passwordautocomplete =off>
< input type =textclass =lp_inputsize =13name =usernamevalue =autocomplete =off>
< input name =loginid =submitformtype =submitclass =ovalue =Logon>
我已经已经创建了一个请求对象,但不知道如何使用它来提交上述内容。
NSURL * url = [NSURL URLWithString:@ https://connect.website.com];
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@POST];
[request setValue:@text / htmlforHTTPHeaderField:@Content-Type];
[request setValue:self.userName forHTTPHeaderField:@username];
[request setValue:self.Password forHTTPHeaderField:@password];
//如何提交此信息?
NSURLConnection * connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[连接开始];
if(connection){
mutData = [NSMutableData data];
解决方案
试试这个
如果您有一个页面与以下形式:
< form name =loginmethod =POSTaction =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 ];
[request setPostValue:@1234forKey:@password]; $ b [请求setPostValue:@AdminforKey:@username];
[请求setPostValue] $ b [request startSynchronous];
它真的可以帮助您。
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];
}
解决方案
Try this
if you have a page http://test.com/form.php with following form:
<form name="login" method="POST" action="action.php">
<input name="username"><br />
<input name="password"><br>
<input type="submit">
</form>
you can use this code, to perform this 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];
It will really help you out.
这篇关于目标C - 提交HTML表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!