2013-05-13 114 views
4

我試圖創建一個訪問第三方API的代理服務器,但他們的開發結束點有證書錯誤。無論如何,使用http.dart時繞過ssl錯誤?使用http繞過證書錯誤

import 'package:http/http.dart' as http; 

Uri url = Uri.parse("https://url-with-ssl-error.com/endpoint"); 
http.get(url).then((response) => print(response.body)); 

,這裏是返回的錯誤:「對等的證書頒發者已被標記爲未受到用戶信任」

Uncaught Error: SocketIOException: RawSecureSocket error (Unexpected handshake error in client) (OS Error: errno = -8172) 
Unhandled exception: 
SocketIOException: RawSecureSocket error (Unexpected handshake error in client) (OS Error: errno = -8172) 
#0  _FutureImpl._scheduleUnhandledError.<anonymous closure> (dart:async/future_impl.dart:207:9) 
#1  Timer.run.<anonymous closure> (dart:async/timer.dart:17:21) 
#2  Timer.run.<anonymous closure> (dart:async/timer.dart:25:13) 
#3  Timer.Timer.<anonymous closure> (dart:async-patch:15:15) 
#4  _Timer._createTimerHandler._handleTimeout (dart:io:6990:28) 
#5  _Timer._createTimerHandler._handleTimeout (dart:io:6998:7) 
#6  _Timer._createTimerHandler.<anonymous closure> (dart:io:7006:23) 
#7  _ReceivePortImpl._handleMessage (dart:isolate-patch:81:92) 
+0

你能展示代碼的相關部分和確切的錯誤嗎? – 2013-05-13 14:35:23

+0

@ZdeslavVojkovic我用代碼編輯我的問題,並返回錯誤 – 2013-05-13 15:34:58

+0

嘗試在get之前添加'SecureSocket.initialize()'。請參閱http://stackoverflow.com/questions/13964492/socketioexception-unexpected-handshake-error-in-client和http://code.google.com/p/dart/issues/detail?id=7541 – 2013-05-13 15:40:40

回答

0

錯誤-8172指

如果您有權訪問原始套接字,則connect方法允許您通過提供onBadCertificate回調來指定在發生錯誤證書的情況下執行的操作。但是,我不確定代碼示例中http對象的確切類型,因此我無法判斷您是否可以解決此問題。我認爲它可能是HttpClient實例,但它沒有帶有URI的get方法,所以我不確定。如果它是你自己的班級,也許你可以訪問底層的安全套接字,所以你仍然可以使用onBadCertificate

此外,對於服務器套接字,您不能依靠隱含的SecureSocket.initialize()調用。你需要call it explicitly with certificate db info

+0

對不起,http是http://pub.dartlang.org/packages/http – 2013-05-13 17:13:43

+0

我簡單看了一下http包,但是我還沒有看到控制壞的證書的方法。 – 2013-05-13 20:01:32

+0

您可以在http://dartbug.com/new上申請http軟件包的功能。謝謝! – 2013-05-14 05:35:13