Torna al Thread

Imports System Imports System.Net Imports System.Net.Sockets Imports System.Text Module Module1 Sub Main() 'scelgo l'host Dim IPHost As IPHostEntry = Dns.Resolve("localhost") 'IPHostEntry(IPHost = Dns.Resolve("localhost")) Console.WriteLine(IPHost.HostName) Dim aliases() As String = IPHost.Aliases 'string []aliases = IPHost.Aliases Dim addr As IPAddress() = IPHost.AddressList 'IPAddress[] addr = IPHost.AddressList Console.WriteLine(addr(0)) Dim ep As EndPoint = New IPEndPoint(addr(0), 80) 'EndPoint ep = new IPEndPoint(addr[0],80) Dim sock As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) 'Socket(sock = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) sock.Connect(ep) If sock.Connected Then Console.WriteLine("OK") Dim ASCII As Encoding = Encoding.ASCII 'Encoding = ASCII = Encoding.ASCII Dim protocol As String = "HTTP/1.0" 'string protocol="HTTP/1.0" ; Dim br As String = "\r\n" 'string br="\r\n" ; Dim target As String = "/phpinfo.php" 'string target="/phpinfo.php" ; Dim req_body As String = "" 'string req_body="" ; req_body += "&to=5" 'req_body+="&to=5"; Dim headers As String = "POST " + target + " " + protocol + br 'string headers="POST "+target+" "+protocol+br ; headers += "Content-Type: application/x-www-form-urlencoded" + br 'headers+="Content-Type: application/x-www-form-urlencoded"+br ; headers += "Content-Length: " + req_body.Length.ToString + br + br 'headers+="Content-Length: "+req_body.Length+br+br ; Dim ByteGet As Byte() = ASCII.GetBytes(headers + req_body) 'Byte[] ByteGet = ASCII.GetBytes(headers+req_body); '( in C# ) ---> Byte[] RecvBytes = new Byte[2256]; Dim RecvBytes(2256) As Byte '= New Byte(2256) '### se faccio cosi mi dice che Byte non ha costruttori.... ### sock.Send(ByteGet, ByteGet.Length, 0) 'sock.Send(ByteGet, ByteGet.Length, 0); Dim bytes As Int32 = sock.Receive(RecvBytes, 0, RecvBytes.Length, 0) 'Int32 bytes = sock.Receive(RecvBytes,0, RecvBytes.Length, 0); Dim strRetPage As String = "" 'string strRetPage=""; strRetPage = ASCII.GetString(RecvBytes, 0, RecvBytes.Length) 'strRetPage = ASCII.GetString(RecvBytes, 0,RecvBytes.Length); Console.WriteLine(strRetPage) strRetPage = Nothing 'strRetPage = null strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes) 'strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes); While bytes > 0 bytes = sock.Receive(RecvBytes, 0, RecvBytes.Length, SocketFlags.Peek) strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes) Console.WriteLine(strRetPage) End While sock.Shutdown(SocketShutdown.Both) sock.Close() 'STOP codice Console.WriteLine() End Sub End Module
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5