'点一下Command4,Winsock返回的数据存放在Text1里面,返回的数据如下:
HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
Transfer-Encoding: chunked
Date: Fri, 01 Dec 2006 03:47:44 GMT
Connection: close0'代码如下,大家帮忙看看是哪里不对Private Sub Command4_Click()
On Error Resume Next
tcpServer.Connect "trans.yninfo.com", 80 '设置主机ip port
DoEvents
End SubPrivate Sub tcpServer_Connect()
'向服务器发送数据 打开主页面
Dim strData As String
strData = ""
strData = strData & "POST /total/RechResultadd/ResultAddForSour.jsp HTTP/1.1" & vbCrLf
strData = strData & "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*" & vbCrLf
strData = strData & "Accept-Encoding: gzip , deflate" & vbCrLf
strData = strData & "Accept-Language: zh-cn" & vbCrLf
strData = strData & "Content-Length: 505" & vbCrLf
strData = strData & "Cache-Control: no-cache" & vbCrLf
strData = strData & "Connection: Keep-Alive" & vbCrLf & vbCrLf
strData = strData & "Content-Type: application/x-www-form-urlencoded" & vbCrLf
strData = strData & "Host: trans.yninfo.com" & vbCrLf
strData = strData & "Referer: http://news.yninfo.com/yunnan/subject/px/index.html" & vbCrLf
strData = strData & "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; Alexa Toolbar; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" & vbCrLf & vbCrLf
strData = strData & "nRid=1164597835463&check1164597835463=云南联通&check1164597835463=前进牛奶&check1164597835463=渤骏装家汉&check1164597835463=拓东酱油&check1164597835463=福林堂&check1164597835463=江东集团&check1164597835463=腾药&check1164597835463=城建股份&check1164597835463=雪兰牛奶&check1164597835463=完美中国&submitok=提交&userName=userName&nRid=1164597835463" & vbCrLf
tcpServer.SendData strData
DoEvents
If tcpServer.State = 7 Then
Text2.Text = "已连接..."
If tcpServer.State = 9 Then
Text2.Text = "连接错误,请检查..."
End If
End IfEnd SubPrivate Sub tcpServer_DataArrival _
(ByVal bytesTotal As Long)
Dim strData() As Byte
ReDim GotDat(0 To bytesTotal - 1)
tcpServer.GetData strData, vbArray + vbByte
Dim strdata2 As String
Dim i As Long
Dim ii As Long
Dim ss As String
Dim s1 As String
For i = 0 To bytesTotal - 1
If AscB(strData(i)) > 127 Then
s1 = Chr(strData(i) * 256 + strData(i + 1))
i = i + 1
Else
s1 = Chr(strData(i))
End If
strdata2 = strdata2 + s1
Next
Text1.Text = strdata2
End Sub
HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
Transfer-Encoding: chunked
Date: Fri, 01 Dec 2006 03:47:44 GMT
Connection: close0'代码如下,大家帮忙看看是哪里不对Private Sub Command4_Click()
On Error Resume Next
tcpServer.Connect "trans.yninfo.com", 80 '设置主机ip port
DoEvents
End SubPrivate Sub tcpServer_Connect()
'向服务器发送数据 打开主页面
Dim strData As String
strData = ""
strData = strData & "POST /total/RechResultadd/ResultAddForSour.jsp HTTP/1.1" & vbCrLf
strData = strData & "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*" & vbCrLf
strData = strData & "Accept-Encoding: gzip , deflate" & vbCrLf
strData = strData & "Accept-Language: zh-cn" & vbCrLf
strData = strData & "Content-Length: 505" & vbCrLf
strData = strData & "Cache-Control: no-cache" & vbCrLf
strData = strData & "Connection: Keep-Alive" & vbCrLf & vbCrLf
strData = strData & "Content-Type: application/x-www-form-urlencoded" & vbCrLf
strData = strData & "Host: trans.yninfo.com" & vbCrLf
strData = strData & "Referer: http://news.yninfo.com/yunnan/subject/px/index.html" & vbCrLf
strData = strData & "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; Alexa Toolbar; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" & vbCrLf & vbCrLf
strData = strData & "nRid=1164597835463&check1164597835463=云南联通&check1164597835463=前进牛奶&check1164597835463=渤骏装家汉&check1164597835463=拓东酱油&check1164597835463=福林堂&check1164597835463=江东集团&check1164597835463=腾药&check1164597835463=城建股份&check1164597835463=雪兰牛奶&check1164597835463=完美中国&submitok=提交&userName=userName&nRid=1164597835463" & vbCrLf
tcpServer.SendData strData
DoEvents
If tcpServer.State = 7 Then
Text2.Text = "已连接..."
If tcpServer.State = 9 Then
Text2.Text = "连接错误,请检查..."
End If
End IfEnd SubPrivate Sub tcpServer_DataArrival _
(ByVal bytesTotal As Long)
Dim strData() As Byte
ReDim GotDat(0 To bytesTotal - 1)
tcpServer.GetData strData, vbArray + vbByte
Dim strdata2 As String
Dim i As Long
Dim ii As Long
Dim ss As String
Dim s1 As String
For i = 0 To bytesTotal - 1
If AscB(strData(i)) > 127 Then
s1 = Chr(strData(i) * 256 + strData(i + 1))
i = i + 1
Else
s1 = Chr(strData(i))
End If
strdata2 = strdata2 + s1
Next
Text1.Text = strdata2
End Sub
注意一下你这句代码,后面多了一个 回车符 & vbCrLf
http://www.dunzip.com/download/GetWebSearch.rar