0

我目前被困在用户使用他的用户名和密码来查看他的数据的部分。我确实尝试了这个网站上的每一条信息,以找出如何让它在没有运气的情况下工作,如果有人能指出我正确的方向,我将不胜感激。

这是我的 .h 文件:

#import <UIKit/UIKit.h>




@interface ePaymentLoginViewController : UIViewController {
IBOutlet UITextField *__weak usernameField;
IBOutlet UITextField *__weak passwordField;
IBOutlet UIButton *__weak loginButton;
IBOutlet UIActivityIndicatorView *__weak loginIndicator;


}

@property (weak, nonatomic) UITextField *usernameField;

@property (weak, nonatomic) UITextField *passwordField;

@property (weak, nonatomic) UIButton *loginButton;

@property (weak, nonatomic) UIActivityIndicatorView *loginIndicator;


- (IBAction) login: (id) sender;


- (IBAction)backButton:(id)sender;

- (IBAction)cancelButton:(id)sender;






@end

这是我的 .m 文件:

#import "ePaymentLoginViewController.h"

@interface ePaymentLoginViewController ()

@end

@implementation ePaymentLoginViewController

@synthesize usernameField;
@synthesize passwordField;
@synthesize loginButton;
@synthesize loginIndicator;





- (IBAction) login: (id) sender
{
NSString *post =[NSString stringWithFormat:@"%@/%@",usernameField.text, passwordField.text];

NSString *hostStr = @"http://ourserver/mobilepay/MobilePayService.svc/verify/%@/%@";
hostStr = [hostStr stringByAppendingString:post];

NSData *dataURL =  [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];    
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];

if([serverOutput isEqualToString:@"text/json"]){

    UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Congrats" message:@"You are authorized" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

    [alertsuccess show];

} else {

    UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Login Failed" message:@"Username or Password Incorrect" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

    [alertsuccess show];

    loginIndicator.hidden = TRUE;
    loginButton.enabled = TRUE;

 [loginIndicator startAnimating];


}

}




- (void)didReceiveMemoryWarning {
// Releases the view if it doesn’t have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren’t in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}




-(IBAction)backButton:(id)sender{

[self dismissViewControllerAnimated:YES completion:nil];

}
-(IBAction)cancelButton:(id)sender{

[self dismissViewControllerAnimated:YES completion:nil];

}



@end    

成功登录后,这是 url 的外观,它将发送 JSON 数据

http://ourserver/mobilepay/MobilePayService.svc/verify/user123/test123    

{
   "Table": [
     {
       "comp_filenum": 1006842,
      "comp_namar": "username123",
      "comp_civid": "100000"
    }
  ],
  "Table1": [
    {
      "tran_num": 30301,
      "inst_val": 1725,
      "balance": 3450,
      "late_amount": 3450,
      "late_inst_no": 2,
      "legal_status": 0,
      "baloon_balance": 0,
      "late_bal_no": 0,
      "remain_bal_no": 0,
      "clienttype": 2,
      "filenumber": 1006842,
      "customername": "username123",
      "civilid": "100000",
      "saleprice": 82800,
      "costprice": 66005,
      "last_receiptnumber": "e22512",
      "last_paydate": "2012-05-02T00:00:00",
      "last_payamount": 1725,
      "paidamount": 79350,
      "remaininginstallment": 16
    },

那么我在这一点上做错了什么,正确的方法是什么。

4

2 回答 2

0

尝试以下行:

NSString *hostStr = [NSString stringWithFormat:@"http://ourserver/mobilepay/MobilePayService.svc/verify/%@/%@",usernameField.text, passwordField.text]; 
NSURL *aURL = [NSURL URLWithString: hostStr]; 
NSLog(@"%@",aURL); // check the log 

NSData *dataURL =  [NSData dataWithContentsOfURL:aURL];
于 2012-06-26T08:34:28.843 回答
0

尝试显示hostStr的值

NSString *post =[NSString stringWithFormat:@"%@/%@",usernameField.text, passwordField.text];

NSString *hostStr = @"http://ourserver/mobilepay/MobilePayService.svc/verify/%@/%@";
hostStr = [hostStr stringByAppendingString:post];

它将显示: http://ourserver/mobilepay/MobilePayService.svc/verify/%@/%@username/password

试试这个:

NSString *hostStr = @"http://ourserver/mobilepay/MobilePayService.svc/verify/%@/%@";

NSString *url = [NSString  stringWithFormat:hostStr,usernameField.text, passwordField.text];
于 2012-06-26T08:35:10.150 回答