2010-04-28 60 views
3

我正在爲iPhone創建一個應用程序,用於從網站獲取特定頁面,但爲了能夠查看此網站,您需要使用用戶名和密碼登錄。UIWebView忽略cookie?

我創造了這個代碼:

NSString *urlAddress = @"http://www.wdg-hamburg.de"; 
NSURL *url = [NSURL URLWithString:urlAddress]; 

NSString *post = @"name=loginname&pass=pass&form_id=user_login&op=Anmelden"; 
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding]; 

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; 

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 
[request setHTTPMethod: @"POST"]; 
[request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
[request setHTTPBody:postData]; 

[vPlan loadRequest:request]; 

但我不是在一個UIWebView登錄!

我登錄NSHTTPCookieStorage到控制檯,它顯示我一點餅乾,但我不得到登錄。

有誰知道我該如何解決呢?

親切的問候,

A. Miladinovic

+0

我有類似的問題。你有沒有設法找到解決方案? – 2010-12-06 07:42:40

回答

1

你試過設置cookie的頭?

NSArray* cookies = [NSArray arrayWithObjects: cookie, nil]; 
NSDictionary * headers = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies]; 
[request setAllHTTPHeaderFields:headers];