使用socket向HTTP服务器发送数据
我正在用 vb 6 编写一个程序。我想将数据发送到我的服务器并获取返回的数据
但我遇到了一个问题:当我发送数据(没有任何错误)时,我的服务器没有答复。
注意:我使用XAMPP作为服务器,浏览器没问题!!!
Private blnConnected As Boolean
Private Sub cmdSend_Click()
Dim str As String
str = "GET /newpass/ HTTP/1.1" & vbNewLine & "Host: localhost" & _
vbNewLine & "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.21) Gecko/20110830 Firefox/3.6.21" & _
vbNewLine & "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & _
vbNewLine & "Accept-Language: en-us,en;q=0.5" & _
vbNewLine & "Accept-Encoding: gzip,deflate" & _
vbNewLine & "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" & _
vbNewLine & "Keep-Alive: 115" & _
vbNewLine & "Connection: keep-alive"
winsock.Protocol = sckTCPProtocol
winsock.RemoteHost = "localhost"
winsock.RemotePort = 80
winsock.Connect
While Not blnConnected
DoEvents
Wend
winsock.SendData str
End Sub
Private Sub winsock_Connect()
blnConnected = True
End Sub
Private Sub winsock_DataArrival(ByVal bytesTotal As Long)
Dim strResponse As String
winsock.GetData strResponse, vbString, bytesTotal
info.Text = strResponse
End Sub
Private Sub winsock_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
winsock.Close
End Sub
I'm writing a program in vb 6. I want to send data to my server and get returned data
but I faced a problem: when I send data( without any error) there is no answer from my server.
Note: I'm using XAMPP as server and it's ok with browser!!!
Private blnConnected As Boolean
Private Sub cmdSend_Click()
Dim str As String
str = "GET /newpass/ HTTP/1.1" & vbNewLine & "Host: localhost" & _
vbNewLine & "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.21) Gecko/20110830 Firefox/3.6.21" & _
vbNewLine & "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & _
vbNewLine & "Accept-Language: en-us,en;q=0.5" & _
vbNewLine & "Accept-Encoding: gzip,deflate" & _
vbNewLine & "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" & _
vbNewLine & "Keep-Alive: 115" & _
vbNewLine & "Connection: keep-alive"
winsock.Protocol = sckTCPProtocol
winsock.RemoteHost = "localhost"
winsock.RemotePort = 80
winsock.Connect
While Not blnConnected
DoEvents
Wend
winsock.SendData str
End Sub
Private Sub winsock_Connect()
blnConnected = True
End Sub
Private Sub winsock_DataArrival(ByVal bytesTotal As Long)
Dim strResponse As String
winsock.GetData strResponse, vbString, bytesTotal
info.Text = strResponse
End Sub
Private Sub winsock_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
winsock.Close
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在最后一个标题后添加 2 个换行符。这将向服务器表明标头已完成。
Try adding 2 newlines after your last header. That will indicate to the server that the headers are complete.