00858:         Dim request As WebRequest
00859:         Dim response As WebResponse
00860:         Dim NotSupportedException1 As System.NotSupportedException
00861:         Dim WebException1 As System.Net.WebException
00862:         TextBox2.Text = "..."
00863:         '
00864:         Try
00865:             'делаем запрос
00866:             request = WebRequest.Create(TextBox1.Text)
00867:             response = request.GetResponse
00868:             TextBox2.Text = "Wait"
00869:             Dim HttpResponse As System.Net.HttpWebResponse = CType(response, HttpWebResponse)
00870:             'разбираем заголовок, пришедший в ответе"
......
00882:             Dim i As Integer
00883:             Dim h(24) As String
00884:             For i = 0 To response.Headers.Count - 1
00885:                 If i < 24 Then
00886:                     h(i * 2) = response.Headers.Keys(i)
00887:                     h(i * 2 + 1) = response.Headers(response.Headers.Keys(i))
00888:                 End If
00889:             Next
......
00914: 
00915:             '
00916:         Catch WebException1          'http://www.aport.r/
00917:             TextBox2.Text = WebException1.Message
00918:         Catch NotSupportedException1 'ttp://www.aport.ru/
00919:             TextBox2.Text = NotSupportedException1.Message
00920:         End Try
00921:         '
00922:         'Теперь начинаем работать с потоком
00923:         '
00924:         'UnicodeEncoding - little-endian (code page 1200) and big-endian (code page 1201)
00925:         'UTF7Encoding - code page 65000.
00926:         'UTF8Encoding - code page 65001.
00927:         'MS-DOS Russian - code page 866.
00928:         'Windows Cyrillic - code page 1251.
00929:         'Macintosh Cyrillic - code page 10007.
00930:         'IBM Cyrillic (primarily Russian) - code page 855.
00931:         'Cyrillic (KOI8-R) - code page 20866.
00932:         'ISO 8859-5 Cyrillic - code page 28595.
00933:         '
00934:         Dim Stream As System.IO.Stream = response.GetResponseStream()
00935:         Dim StreamReader As New System.IO.StreamReader(Stream, System.Text.Encoding.GetEncoding(CInt(TextBox18.Text)))
00936:         '
00937:         TextBox16.Text = StreamReader.CurrentEncoding.WindowsCodePage()        'контроль
......
00940:         '
00941:         If Stream.CanRead Then
00942:             Dim variant1 As Integer = 1
00943:             Select Case variant1
00944:                 Case 1
00945:                     'на форму и в файл выводится без русских букв
00946:                     Dim Memory As String = StreamReader.ReadToEnd
00947:                     TextBox14.Text = Memory
00948:                     FileOpen(1, "1.txt", OpenMode.Output, OpenAccess.Write)
00949:                     Print(1, Memory)
00950:                     FileClose(1)
00951:                 Case 2
00952:                     'или вот так без StreamReder'a и перекодировки
00953:                     Dim code1, code2 As System.Text.Encoding
00954:                     Dim numBytesToRead As Integer = response.ContentLength
00955:                     Dim numBytesRead As Integer = 0
00956:                     Dim bytes(10000) As Byte
00957:                     While numBytesToRead > 0
00958:                         Dim n As Integer = Stream.Read(bytes, numBytesRead, numBytesToRead)
00959:                         If n = 0 Then
00960:                             Exit While
00961:                         End If
00962:                         numBytesRead += n
00963:                         numBytesToRead -= n
00964:                     End While
00965:                     Dim fs As New System.IO.FileStream("2.txt", IO.FileMode.Create)
00966:                     Dim bw As New System.IO.BinaryWriter(fs, System.Text.Encoding.GetEncoding(CInt(TextBox18.Text)))
00967:                     bw.Write(bytes)
00968:                     bw.Close()
00969:                     fs.Close()


Comments ( )
Link to this page: //www.vb-net.com/dotnet/tour16/proxy.htm
< THANKS ME>