2013-05-13 116 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