可能重复:
如何创建与 xml 网络服务连接的注册表单?
我必须创建一个与 Web 服务相关的注册和登录表单。如何将注册详细信息发送到 Web 服务?以及如何使用网络服务中的用户名和密码登录?帮我。
可能重复:
如何创建与 xml 网络服务连接的注册表单?
我必须创建一个与 Web 服务相关的注册和登录表单。如何将注册详细信息发送到 Web 服务?以及如何使用网络服务中的用户名和密码登录?帮我。
对于注册表:
您必须进行简单的 XML 解析,在其中您将执行您的链接并传递用户在注册期间将填写的数据,然后您必须通过 XML 解析将该数据发送到 Web 服务
首先在这里学习Web Service的基础知识
本文将使您很好地理解如何在您的 iPhone 应用程序中与 XML Web 服务进行通信,并且这些示例将为在您自己的项目中使用其他 Web 服务提供坚实的基础。
http://www.allappsdevelopers.com/TopicDetail.aspx?TopicID=97963e2d-37a5-4e48-b434-3fced80d2b55
例子:
-(UITextField*) customTextfield:(NSString*)fieldType textName:(NSString*)str initFrame:(CGRect)frame
{
UITextField *customField = [[UITextField alloc] initWithFrame:frame];
customField.delegate = self;
customField.adjustsFontSizeToFitWidth = NO;
customField.borderStyle = UITextBorderStyleRoundedRect;
customField.textColor = [UIColor blackColor];
customField.clearButtonMode = UITextFieldViewModeWhileEditing;
customField.clearsOnBeginEditing = NO;
customField.autocapitalizationType = UITextAutocapitalizationTypeNone;
customField.autocorrectionType = UITextAutocorrectionTypeNo;
customField.enablesReturnKeyAutomatically = YES;
customField.returnKeyType = UIReturnKeyDefault;
customField.placeholder = NSLocalizedString(str, nil);
customField.keyboardType = UIKeyboardTypeDefault;
return customField;
}
- (void)viewDidLoad
{
txtfname = [self customTextfield:@"" textName:@"" initFrame:CGRectMake(120, 75, 160, 30)];
[self.view addSubview:txtfname];
txtlastname = [self customTextfield:@"" textName:@"" initFrame:CGRectMake(120, 115, 160, 30)];
[self.view addSubview:txtlastname];
txtemail = [self customTextfield:@"" textName:@"" initFrame:CGRectMake(120, 155, 160, 30)];
[self.view addSubview:txtemail];
txtpwd = [self customTextfield:@"" textName:@"" initFrame:CGRectMake(120, 195, 160, 30)];
txtpwd.secureTextEntry=YES;
[self.view addSubview:txtpwd];
txtRePwd= [self customTextfield:@"" textName:@"" initFrame:CGRectMake(120, 235, 160, 30)];
txtRePwd.secureTextEntry=YES;
[self.view addSubview:txtRePwd];
}
提交表格
-(void) fieldValidate
{
NSString *emailRegEx =@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *regExpred =[NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
BOOL myStringCheck = [regExpred evaluateWithObject:txtemail.text];
if ([txtfname.text length]==0) {
[self callAlert:@"Please Enter First Name"];
[txtfname becomeFirstResponder];
return;
}
else if ([txtlastname.text length]==0) {
[self callAlert:@"Please Enter Last Name"];
[txtlastname becomeFirstResponder];
return;
}
else if(!myStringCheck){
[self callAlert:@"Email address should be in yourname@domainname.com format"];
[txtemail becomeFirstResponder];
return;
}
else if ([txtpwd.text length]==0) {
[self callAlert:@"Password should have atleast 1 characters"];
[txtpwd becomeFirstResponder];
return;
}
else if ([txtRePwd.text length]==0) {
[self callAlert:@"Password should have atleast 1 characters"];
// [txtRePwd becomeFirstResponder];
return;
}
else if (![txtpwd.text isEqualToString:txtRePwd.text])
{
[self callAlert:@"Password And Repassword Mismatched"];
[txtpwd becomeFirstResponder];
return;
}
[txtfname resignFirstResponder];
[txtlastname resignFirstResponder];
[txtemail resignFirstResponder];
[txtpwd resignFirstResponder];
[txtRePwd resignFirstResponder];
NSString *Restrqst = [NSString stringWithFormat:@"<user>\n"
"<account_attributes><first_name>%@</first_name></account_attributes>\n"
"<lastName>%@</lastName>\n"
"<email>%@</email>\n"
"<password>%@</password>\n"
"<password_confirmation>%@</password_confirmation>\n"
"</user>\n",txtfname.text,txtlastname.text,txtemail.text,txtpwd.text];
NSURL *RestURL = [NSURL URLWithString:@"www.xxxx.com/signup"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:RestURL];
[request setDelegate:self];
request.shouldPresentCredentialsBeforeChallenge = YES ;
[request addRequestHeader:@"Content-Type" value:@"application/xml"];
[request appendPostData:[Restrqst dataUsingEncoding:NSUTF8StringEncoding]];
[request setRequestMethod:@"POST"];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestWentWrong:)];
[request startAsynchronous];
}