The output stream is obtained by using the static File method Create.Compile and run in Windows:
E: work>Csc CopyTester. cs StringExtensions. csMicrosoft (R) Visual C #2010 compiler 4.0.30319.1 copyright (C) Microsoft Corporation. All rights reserved. E: work>CopyTester https://github.com/mono/xsp/zipball/master mono-xsp.zipE: work>CopyTester http://mysql.ntu.edu.tw/Downloads/Connector-Net/mysql-connector-net-6.5.4-noinstall.zip mysql-connector.zipE: work>CopyTester ftp://ftp.ntu.edu.tw/pub/MySQL/Downloads/Connector-Net/mysql-connector-net-6.5.4-noinstall.zip mysql-connector.2.zipE: work>CopyTester file: /// E:/work/mysql-connector.zip mysql-connector.3.zipE: work>CopyTester mysql-connector.zip mysql-connector.4.zipE: work>Dir *. zipMono-xsp.zip2012/468,024 mysql-connector.2.zip2012/03/11 mysql-connector.3.zip2012/4,176,361 mysql-connector.4.zip2012/03/11 4,176,361 mysql-connector.zip/03/11 4,176,361
The above tests respectively read network data using https, http, ftp, and file protocols, and read data from local disks. Note that the file protocol actually reads data from the local disk.
Compile and run in Linux:
ben@vbox:~/work> dmcs CopyTester.cs StringExtensions.csben@vbox:~/work> mono CopyTester.exe http://mysql.ntu.edu.tw/Downloads/Connector-Net/mysql-connector-net-6.5.4-noinstall.zip mysql-connector.zipben@vbox:~/work> mono CopyTester.exe ftp://ftp.ntu.edu.tw/pub/MySQL/Downloads/Connector-Net/mysql-connector-net-6.5.4-noinstall.zip mysql-connector.2.zipben@vbox:~/work> mono CopyTester.exe file:///home/ben/work/mysql-connector.zip mysql-connector.3.zipben@vbox:~/work> mono CopyTester.exe mysql-connector.zip mysql-connector.4.zipben@vbox:~/work> ls -l *.zip-rw-r--r-- 1 ben users 4176361 Mar 11 09:54 mysql-connector.2.zip-rw-r--r-- 1 ben users 4176361 Mar 11 10:01 mysql-connector.3.zip-rw-r--r-- 1 ben users 4176361 Mar 11 10:01 mysql-connector.4.zip-rw-r--r-- 1 ben users 4176361 Mar 11 09:53 mysql-connector.zip
In Windows, the https data stream on the network can be normally read, but fails in Linux:
ben@vbox:~/work> mono CopyTester.exe https://github.com/mono/xsp/zipball/master mono-xsp.zipUnhandled Exception: System.Net.WebException: Error getting response stream (Write: The authentication or decryption has failed.): SendFailure ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010a at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection certificates) [0x00000] in :0 at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 () [0x00000] in :0 at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () [0x00000] in :0 at (wrapper remoting-invoke-with-check) Mono.Security.Protocol.Tls.Handshake.HandshakeMessage:Process () at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg) [0x00000] in :0 at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in :0 --- End of inner exception stack trace --- at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in :0 --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in :0 at System.Net.HttpWebRequest.GetResponse () [0x00000] in :0 at Skyiv.StringExtensions.GetHttpStream (System.Uri uri) [0x00000] in :0 at Skyiv.StringExtensions.GetInputStream (System.String fileNameOrUri, System.String user, System.String password) [0x00000] in :0 at Skyiv.Test.CopyTester.Main (System.String[] args) [0x00000] in :0[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.WebException: Error getting response stream (Write: The authentication or decryption has failed.): SendFailure ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010a at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection certificates) [0x00000] in :0 at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 () [0x00000] in :0 at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () [0x00000] in :0 at (wrapper remoting-invoke-with-check) Mono.Security.Protocol.Tls.Handshake.HandshakeMessage:Process () at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg) [0x00000] in :0 at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in :0 --- End of inner exception stack trace --- at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in :0 --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in :0 at System.Net.HttpWebRequest.GetResponse () [0x00000] in :0 at Skyiv.StringExtensions.GetHttpStream (System.Uri uri) [0x00000] in :0 at Skyiv.StringExtensions.GetInputStream (System.String fileNameOrUri, System.String user, System.String password) [0x00000] in :0 at Skyiv.Test.CopyTester.Main (System.String[] args) [0x00000] in :0
I don't know if it is my openSUSE 12.1 operating system or the Mono 2.10.6 runtime environment. Some configuration is required to meet the https security verification requirements. However, I have not made any special configuration in Windows. In addition, you can use the wget command in Linux to download https data:
ben@vbox:~/work> wget https://github.com/mono/xsp/zipball/masterasking libproxy about url 'https://github.com/mono/xsp/zipball/master'libproxy suggest to use 'direct://'--2012-03-11 13:48:32-- https://github.com/mono/xsp/zipball/masterResolving github.com (github.com)... 207.97.227.239Connecting to github.com (github.com)|207.97.227.239|:443... connected.HTTP request sent, awaiting response... 302 FoundLocation: https://nodeload.github.com/mono/xsp/zipball/master [following]asking libproxy about url 'https://nodeload.github.com/mono/xsp/zipball/master'libproxy suggest to use 'direct://'--2012-03-11 13:48:34-- https://nodeload.github.com/mono/xsp/zipball/masterResolving nodeload.github.com (nodeload.github.com)... 207.97.227.252Connecting to nodeload.github.com (nodeload.github.com)|207.97.227.252|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 468024 (457K) [application/octet-stream]Saving to: `master'100%[======================================>] 468,024 46.5K/s in 17s2012-03-11 13:48:54 (27.0 KB/s) - `master' saved [468024/468024]ben@vbox:~/work> mv master mono-xsp.zip
In this case, the HttpWebRequest class in the Mono environment may need some settings to read https data. If any of you know, please let me know in the comments in this article. Thank you.