2012-06-26 278 views
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 
    }, 

那麼,我在這一點做錯了什麼,以及什麼是正確的方式來做到這一點。

回答

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]; 
+0

我試過它沒有工作 –

+0

@ MoayadAl-Edan:檢查更新的答案... – Maulik

+0

謝謝你更近一步,URL有錯誤的格式,仍然不知道如何得到它來驗證它假設從JSON數據獲取服務器如果用戶名和密碼是正確的,他們的方式或部分即時消失 –

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]; 
+0

我試過沒有工作 –

+0

有什麼不對? hostStr值是什麼? – malinois

+0

你確實發生的權利,雖然我仍然在試圖弄清楚爲什麼它不會將數據加載到日誌區 –