Получилось вот что:
Dim wc As New System.Net.WebClient
Dim Stream As System.IO.Stream
Try
 Stream = wc.OpenRead("http://" & Specific.IP_add _  
  "/hp/device/this.LCDispatcher?dispatch=html&cat=0&pos=1") 
 Using sr As New System.IO.StreamReader(Stream)
  str = sr.ReadToEnd()
  Stream.Close()
 End Using
 Return CType(CountStr, Integer)
Catch ex As Exception
 Dim errorstring = ex.Message
End TryУ принтера HP4350 без проблем считалась страница, а вот у HP 4300 никак.
Ошибка была следующая :
"Сервер нарушил протокол. Section=ResponseHeader Detail=Недопустимое имя заголовка"
Решение удалось найти. Необходимо в файле web.config внести следующие изменения:
<configuration>
<system.net>
<settings>
<httpwebrequest useunsafeheaderparsing="true">
<settings>
<system.net>
<configuration>
С принтером 4515 тоже не очень гладко получилось , так как WEB интерфейс был доступен по протоколу https. Возникало следующее исключение:
"Базовое соединение закрыто Не удалось установить доверительные отношения для защищенного канала SSL TLS". Вот по этой ссылке сделал.
http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/c98ea134-c582-4c2a-8c42-d7e31f7fe389
Итак определяем функцию, котрая возвращает всегда "True"
Private Function ValidateCertificate(ByVal sender As Object, _
  ByVal certificate As  X509Certificate, ByVal chain As X509Chain, _
  ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
  Return True
End Function
А вот ее вызов
Dim wc As New System.Net.WebClient
Dim Stream As System.IO.Stream
Try
 System.Net.ServicePointManager.ServerCertificateValidationCallback = _
 New System.Net.Security.RemoteCertificateValidationCallback AddressOf _
 ValidateCertificate)
 Dim myUri As New Uri("https://" & Specific.IP_address _ &  "/hp/device/this.LCDispatcher?nav=hp.Config")
 Dim mySP As System.Net.ServicePoint = _
     System.Net.ServicePointManager.FindServicePoint(myUri)
 Stream = wc.OpenRead(myUri)
 Using sr As New System.IO.StreamReader(Stream)
 str = sr.ReadToEnd()
 Stream.Close()
 End Using
 Return CType(CountStr, Integer)
Catch ex As Exception
 Dim errorstring = ex.Message
End Try
 
 
Комментариев нет:
Отправить комментарий