17,741
社区成员
发帖
与我相关
我的任务
分享
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim endPoint As New IPEndPoint(IPAddress.Parse("10.255.1.100"), 80)
Dim s As New Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
s.Connect(endPoint)
If s.Connected Then
dim data as string="xxxxxxxx"
Dim ascii As Encoding = System.Text.Encoding.UTF8
Dim buf As New StringBuilder
buf.Append("POST /httpServlet HTTP/1.1" & vbCrLf)
buf.Append("Content-Type: application/x-www-form-urlencoded" & vbCrLf)
buf.Append("Connection: Keep-Alive" & vbCrLf)
buf.Append("Content-Length: " & data.Length & vbCrLf & vbCrLf & vbCrLf)
buf.Append(data & vbCrLf)
Dim bytesSent As [Byte]() = ascii.GetBytes(buf.ToString)
Dim bytesReceived(4096) As [Byte]
s.Send(bytesSent, bytesSent.Length, 0)
Dim bytes As Int32
Dim page As [String] = ""
Dim i As Integer = 0
bytes = s.Receive(bytesReceived, bytesReceived.Length, 0)
page = page + System.Text.Encoding.GetEncoding("GB2312").GetString(bytesReceived, 0, bytes)
txtLog.Text = page.ToString
'想继续发送就不行了,发现连接已经被断开了。。。
s.Send(bytesSent, bytesSent.Length, 0)
End If
End Sub