在iphone应用程序中使用xml web服务创建注册和登录表单

在iphone应用程序中使用xml web服务创建注册和登录表单,iphone,ios,xcode,Iphone,Ios,Xcode,可能重复: 我必须创建一个与web服务相关的注册和登录表单。如何将注册详细信息发送到web服务?如何使用web服务的用户名和密码登录?帮助我。有关注册表: 您必须执行简单的XML解析,在该解析中,您将执行链接并传递用户将在注册期间填写的数据,然后您必须通过XML解析将该数据发送到web服务 这篇文章将让您很好地理解如何在iPhone应用程序中与XML Web服务通信,这些示例将为您自己项目中的其他Web服务提供一个坚实的基础。p> 例如: -(UITextField*) customText

可能重复:


我必须创建一个与web服务相关的注册和登录表单。如何将注册详细信息发送到web服务?如何使用web服务的用户名和密码登录?帮助我。

有关注册表:


您必须执行简单的XML解析,在该解析中,您将执行链接并传递用户将在注册期间填写的数据,然后您必须通过XML解析将该数据发送到web服务

这篇文章将让您很好地理解如何在iPhone应用程序中与XML Web服务通信,这些示例将为您自己项目中的其他Web服务提供一个坚实的基础。p>

例如:

-(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];

   }
-(无效)字段验证
{
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];
如果([txtfname.text length]==0){
[self callAlert:@“请输入名字”];
[txtfname成为第一响应者];
返回;
}
else if([txtlastname.text length]==0){
[self callAlert:@“请输入姓氏”];
[txtlastname成为第一响应者];
返回;
}
else if(!myStringCheck){
[self callAlert:@”电子邮件地址应位于yourname@domainname.com格式“];
[TXTMail成为第一响应者];
返回;
}
else if([txtpwd.text length]==0){
[self callAlert:@“密码应至少包含1个字符”];
[txtpwd成为第一响应者];
返回;
}
else if([txtRePwd.text length]==0){
[self callAlert:@“密码应至少包含1个字符”];
//[txtRePwd成为第一响应者];
返回;
}
else if(![txtpwd.text isEqualToString:txtRePwd.text])
{
[self callAlert:@“密码和重新密码不匹配”];
[txtpwd成为第一响应者];
返回;
}
[txtfname辞职第一响应者];
[txtlastname辞职firstresponder];
[TXTMail辞职第一响应者];
[txtpwd辞职第一响应者];
[txtRePwd辞职第一响应者];
NSString*RestQST=[NSString stringWithFormat:@“\n”
“%@\n”
“%@\n”
“%@\n”
“%@\n”
“%@\n”
“\n”、txtfname.text、txtlastname.text、txtmail.text、txtpwd.text];
NSURL*RestURL=[NSURL URLWithString:@“www.xxxx.com/signup”];
ASIHTTPRequest*请求=[AsiHttpRequestRequestWithURL:RestURL];
[请求setDelegate:self];
request.shouldPresentCredentialsBeforeChallenge=是;
[请求addRequestHeader:@“内容类型”值:@“应用程序/xml”];
[请求appendPostData:[RestQST dataUsingEncoding:NSUTF8StringEncoding];
[请求设置请求方法:@“POST”];
[请求setDidFinishSelector:@selector(请求完成:)];
[RequestSetDidFailSelector:@selector(RequestWentRong:)];
[请求启动同步];
}

Hi,我已经完成了一些xml解析应用程序。我还没有创建登记表。我不知道如何将用户名、密码等发送到web服务。请尝试上面的示例谢谢在线。我将尝试使用此代码此代码正在工作。非常感谢,怎么了?请给我一个示例代码,你知道XML解析吗?在解析过程中,在传递链接的地方,必须传递数据