2014-11-01 140 views
1

我想調用以下web service,但想知道如何傳遞用戶名和密碼並獲得響應。將用戶名和密碼傳遞到Web服務

+0

る新的iOS中,在之前你永遠與web服務工作 – 2014-11-01 06:28:08

+0

可以u顯示烏爾完整的Web服務的名稱,什麼是通過鍵值 – 2014-11-01 06:29:16

+0

是即時通訊與網絡服務但Web服務的新工作。我沒有這樣的憑據。 – user3189586 2014-11-01 06:32:10

回答

0
@interface ViewController() 
{ 
NSURLConnection *clearSession; 
NSMutableData *receivedData; 
} 


- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 

[self clearsession]; 
} 



-(void)clearsession 

{ 



NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:@"https://mybusiness.expressoft.eu/webserviceintegration/v1/myshop/MyShopDataService.svc/"]]; 




NSString *requestString = [NSString stringWithFormat:@"Username=karthik&Password=abcdesg",nil]; 


NSLog(@" RequestString for get card details: %@",requestString); 

NSMutableData *requestData =[NSMutableData dataWithBytes:[requestString UTF8String] length: [requestString length]]; 

[request setHTTPMethod: @"POST"]; 

[request setHTTPBody: requestData]; 
clearSession = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 

if (clearSession) { 
    NSLog(@"data sent "); 
} else 
{ 
    NSLog(@"Not sent"); 
} 

[clearSession start]; 


} 





-(void)connection:(NSConnection*)conn didReceiveResponse:(NSURLResponse *)response 
{ 
if (receivedData == NULL) 
{ 
    receivedData = [[NSMutableData alloc] init]; 
} 
[receivedData setLength:0]; 



} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 

[receivedData appendData:data]; 



} 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
    NSLog(@"Connection failed! Error - %@ %@", 
     [error localizedDescription], 
     [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]); 

UIAlertView *customAlert = [[UIAlertView alloc]initWithTitle:@"No NetWork" message:@"Interet Connection is Lost" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
[customAlert show]; 


} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 

if (connection==clearSession) 
{ 

    NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:receivedData options: kNilOptions error:nil]; 
    NSString *tmp=[[NSString alloc]initWithData:receivedData encoding:NSUTF8StringEncoding]; 
    NSLog(@"%@", tmp); 
    NSLog(@" parsing JSON of add checkout: %@", jsonDict); 


} 

} 
+0

試試這個如果u沒有答案的東西,我希望用U – 2014-11-01 13:50:03

+0

使用的Web服務是WCF數據服務類型和使用的OData協議尋址和更新資源。 ACCES通過認證報頭實現,所述通信協議(端點結合)是HTTP請求(的WebHttpBinding) – user3189586 2014-11-03 06:03:08

+0

,並且從每個頭的請求必須以「基本用戶:密碼」中的「授權」密鑰格式。對於測試,用戶名是abc和密碼abc。 – user3189586 2014-11-03 06:05:23

相關問題