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

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 に答える
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 に答える