1,502
社区成员
发帖
与我相关
我的任务
分享
private sub timer1_timer()
timer1.enabled=false
winsock1.close
doevents
call xxxxxxxxx '这里的xxxxx是更换URL并调用connect的过程
end sub
Private Sub Winsock1_Close()
Close #1
timer1.enabled=true
End Sub
'窗体中一个Winsock1,一个Command1
Option Explicit
Dim Buff() As Byte
Dim IsData As Boolean '是否是数据
Private Sub Command1_Click()
Winsock1.Connect "photo.pchome.com.tw", 80
End Sub
Private Sub Winsock1_Connect()
Dim HTTPStr As String
HTTPStr = "GET http://photo.pchome.com.tw/s13/c/h/chencan0814/book301/p130133146978.jpg HTTP/1.1" & vbCrLf & _
"Connection: Close" & vbCrLf & _
"Host: photo.pchome.com.tw" & vbCrLf & _
"Accept: */*" & vbCrLf & _
"Pragma: no -cache" & vbCrLf & _
"cache -Control: no -cache" & vbCrLf & _
"Referer: http://photo.pchome.com.tw/chencan0814/130133146978" & vbCrLf & _
"User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2)" & _
vbCrLf & vbCrLf
Winsock1.SendData HTTPStr
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
'HTTP/1.1 200 OK
'Date: Tue, 10 May 2011 13:15:45 GMT
'Server: Apache
'Last-Modified: Mon, 28 Mar 2011 16:57:49 GMT
'ETag: "10fe2916-1b265-49f8dd800c042"
'Accept -Ranges: bytes
'Content-Length: 111205
'Connection: Close
'Content-Type: image/jpeg
Dim tmpByte() As Byte, I As Long, J As Long, K As Long
If bytesTotal > 0 Then
Winsock1.GetData tmpByte
If IsData = False Then
Debug.Print StrConv(tmpByte(), vbUnicode)
For I = 0 To UBound(tmpByte) - 3
If tmpByte(I) = 13 And tmpByte(I + 1) = 10 And tmpByte(I + 2) = 13 And tmpByte(I + 3) = 10 Then '两个回车是HTTP头结束的标志.
IsData = True
Open "d:\11.jpg" For Binary As #1 '打开文件
If I + 4 < UBound(tmpByte) - 1 Then '如果后面还有数据就写入
I = I + 4
K = -1
For J = I To UBound(tmpByte)
K = K + 1
tmpByte(K) = tmpByte(J)
Next
ReDim Preserve tmpByte(K)
Put #1, , tmpByte()
End If
Exit For
End If
Next
Else
Put #1, , tmpByte()
End If
End If
End Sub
Private Sub Winsock1_Close()
Close #1
End Sub