我試圖使用StackExchange API的隱式身份驗證,因此我需要將用戶發送到https://www.stackexchange.com/oauth?client_id=...&scope=...&redirect_uri=...
(使用實際值而不是'...')。很簡單,只需在Interface Builder中拖出一個WebView,然後執行WebFrameLoadDelegate
協議中的-webView:didFinishLoadForFrame:
即可跟蹤我們是否已經在redirect_uri
。 那就像我想要的那樣工作。但是WebView內部沒有。從stackexchange.com/oauth
錯誤頁面:在Mac OS X中使用WebView查看HTTPS頁面
Application Login Failure
An error occurred while login into an application.
Error Details:
error: invalid_request
error description: OAuth request must be over HTTPS
但我開始URL以https://
:
- (void)awakeFromNib {
NSString *oauthAddress = @"https://www.stackexchange.com/oauth?client_id=...&scope=...&redirect_uri=...";
[loginWebView setMainFrameURL:oauthAddress];
}
我找不到說你必須做別的事情啓用HTTPS在標準的WebView任何源。
它是由內部的WebView引起的:在-webView:didFinishLoadForFrame:
我NSLog()
「當前的URL:
- (void)webView:(WebView *)webView didFinishLoadForFrame:(WebFrame *)webFrame {
NSString *currentURL = [[[[webFrame dataSource] request] URL] absoluteString];
NSLog(@"-webView:didStartProvisionalLoadForFrame:");
NSLog(@"Current URL: %@", currentURL);
if ([currentURL hasPrefix:@"https://stackexchange.com/oauth/login_success"]) {
NSLog(@"We did login!");
}
}
輸出:
2013-03-05 15:31:55.493 MacOverflow[2164:a0f] -webView:didStartProvisionalLoadForFrame:
2013-03-05 15:31:55.495 MacOverflow[2164:a0f] Current URL: http://stackexchange.com/oauth?client_id=...scope=...&redirect_uri=...
什麼? WebKit從URL的協議部分刪除了's'!如何阻止WebKit這樣做?我在WebView上搜索了Apple的文檔(用Cmd + f)'https'(0個匹配),'ssl'(0個匹配),甚至'安全'(再次匹配0個)。我有點卡在這裏,但它一定是可能的。提供這樣一個複雜的瀏覽器控制將是荒謬的,但迫使開發人員編寫一個支持https
(現在很常見的IMO)的副本!
如何使用WebKit的WebView創建HTTPS請求?
這似乎與Webkit沒有關係,而是與堆棧交換有關。 它可以很好地與任何其他網站(嘗試與Facebook和檢查URL)。 – 2013-03-05 17:56:03