用了以下代码,实现下载网站上某个文件的功能:
Private Sub Command1_Click()
Me.Caption = "Wait..."
Command1.Enabled = False
Dim bytData() As Byte
bytData() = Inet1.OpenURL("http://www.microsoft.com/library/homepage/images/init_dotnet.gif", icByteArray)
Open App.Path & "\example.gif" For Binary Access Write As #1
Put #1, , bytData()
Close #1
Me.Caption = "Success!"
MsgBox "Image downloaded and saved."
Command1.Enabled = True
End Sub没问题。
但把url改为 这个页面(http://dpshow.163.com/showopus.php?opus_id=47309)上的某张图片地址,如:
bytData() = Inet1.OpenURL("http://61.177.95.230/upload/opus/20051115/172362.jpg", icByteArray) ,问题就出现了。
原因是该网站禁止从其他位置直接访问他上面的图片资源,所以直接访问http://61.177.95.230/upload/opus/20051115/172362.jpg 的结果是返回一个提示页面,没有获取到想要的图片。
如你有办法解决 请写出你的代码,运行通过给分
Private Sub Command1_Click()
Me.Caption = "Wait..."
Command1.Enabled = False
Dim bytData() As Byte
bytData() = Inet1.OpenURL("http://www.microsoft.com/library/homepage/images/init_dotnet.gif", icByteArray)
Open App.Path & "\example.gif" For Binary Access Write As #1
Put #1, , bytData()
Close #1
Me.Caption = "Success!"
MsgBox "Image downloaded and saved."
Command1.Enabled = True
End Sub没问题。
但把url改为 这个页面(http://dpshow.163.com/showopus.php?opus_id=47309)上的某张图片地址,如:
bytData() = Inet1.OpenURL("http://61.177.95.230/upload/opus/20051115/172362.jpg", icByteArray) ,问题就出现了。
原因是该网站禁止从其他位置直接访问他上面的图片资源,所以直接访问http://61.177.95.230/upload/opus/20051115/172362.jpg 的结果是返回一个提示页面,没有获取到想要的图片。
如你有办法解决 请写出你的代码,运行通过给分
Host: 61.177.95.230
Accept: */*
Referer: http://dpshow.163.com/showopus.php?opus_id=47309
User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)
Pragma: no-cache
Cache-Control: no-cache
Connection: close我用flashget可以下载
因为模拟了一个东西
Referer:http://dpshow.163.com/showopus.php?opus_id=47309
也就是说 用传递Referer文件头 给163的服务器一个错觉
让它以为是从163的网站下载的
这样就没问题了
但困惑的是一般判断REFERER是在脚本里做的,而LZ的目标是一个图片文件,也就是说已经绕过了PHP文件,对方怎么还能检验REFERER,难道WEB应用服务上也能设置是否检查该关键词的内容?IIS好象没这个设置项目。
可能是他们自己开发的
连脚本语言都可以判断REFERER 那么服务器判断更加可以了
因为REFERER这些头文件数据本来就是服务器获取以后传给脚本的
Option ExplicitPrivate Sub Form_Load()
txtFile.Text = App.Path & "\172362.jpg"
txtUrl.Text = "http://61.177.95.230/upload/opus/20051115/172362.jpg"
txtReferer.Text = "http://dpshow.163.com/showopus.php?opus_id=47309"
End SubPrivate Sub Command1_Click()
Dim strUrl As String 'Á´½Ó
Dim strReferer As String
Dim strHost As String 'Ö÷»ú
Dim strCookie As String 'cookie
Dim intPost As Integer
Dim strHead As String 'Í·
'ÖØй¹ÔìÇëÇóÍ·
strUrl = txtUrl.Text
strReferer = txtReferer.Text
If LCase(Left(strUrl, 7)) <> "http://" Then strUrl = "http://" & strUrl
intPost = InStr(8, strUrl, "/")
If intPost > 0 Then
strHost = Mid(strUrl, 8, intPost - 8)
strUrl = Right(strUrl, Len(strUrl) - intPost)
Else
strHost = Mid(strUrl, 8, Len(strUrl) - 8)
End If
' strHead = "GET " & strUrl & " HTTP/1.0" & vbCrLf
' & "Host: " & strHost & vbCrLf
strHead = "Accept: */*" & vbCrLf _
& "Referer: " & strReferer & vbCrLf _
& "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Maxthon; .NET CLR 1.1.4322)" & vbCrLf _
& "Pragma: no-cache" & vbCrLf _
& "Cache-Control: no-cache"
' & vbCrLf _
' & "Connection: close" & vbCrLf
Debug.Print strHead
InetHttp.Execute txtUrl.Text, "Get", "", strHead
End Sub
Private Sub InetHttp_StateChanged(ByVal State As Integer)
Dim Buff() As Byte
Select Case State
Case icNone 'ÎÞ״̬¿É±¨¸æ¡£
Debug.Print "ÎÞ״̬¿É±¨¸æ¡£"
Case icResolvingHost '¸Ã¿Ø¼þÕýÔÚ²éѯËùÖ¸¶¨µÄÖ÷»úµÄ IP µØÖ·¡£
Debug.Print "¸Ã¿Ø¼þÕýÔÚ²éѯËùÖ¸¶¨µÄÖ÷»úµÄ IP µØÖ·¡£"
Case icHostResolved '¸Ã¿Ø¼þÒѳɹ¦µØÕÒµ½ËùÖ¸¶¨µÄÖ÷»úµÄ IP µØÖ·¡£
Debug.Print "¸Ã¿Ø¼þÒѳɹ¦µØÕÒµ½ËùÖ¸¶¨µÄÖ÷»úµÄ IP µØÖ·¡£"
Case icConnecting '¸Ã¿Ø¼þÕýÔÚÓëÖ÷»úÁ¬½Ó¡£
Debug.Print "¸Ã¿Ø¼þÕýÔÚÓëÖ÷»úÁ¬½Ó¡£"
Case icConnected '¸Ã¿Ø¼þÒÑÓëÖ÷»úÁ¬½Ó³É¹¦¡£
Debug.Print "¸Ã¿Ø¼þÒÑÓëÖ÷»úÁ¬½Ó³É¹¦¡£"
Case icRequesting '¸Ã¿Ø¼þÕýÔÚÏòÖ÷»ú·¢ËÍÇëÇó¡£
Debug.Print "¸Ã¿Ø¼þÕýÔÚÏòÖ÷»ú·¢ËÍÇëÇó¡£"
Case icRequestSent '¸Ã¿Ø¼þ·¢ËÍÇëÇóÒѳɹ¦¡£
Debug.Print "¸Ã¿Ø¼þ·¢ËÍÇëÇóÒѳɹ¦¡£"
Case icReceivingResponse '¸Ã¿Ø¼þÕýÔÚ½ÓÊÕÖ÷»úµÄÏìÓ¦¡£
Debug.Print "¸Ã¿Ø¼þÕýÔÚ½ÓÊÕÖ÷»úµÄÏìÓ¦¡£"
Case icResponseReceived '¸Ã¿Ø¼þÒѳɹ¦µØ½ÓÊÕµ½Ö÷»úµÄÏìÓ¦¡£
Debug.Print "¸Ã¿Ø¼þÒѳɹ¦µØ½ÓÊÕµ½Ö÷»úµÄÏìÓ¦¡£"
Case icDisconnecting '¸Ã¿Ø¼þÕýÔÚ½â³ýÓëÖ÷»úµÄÁ¬½Ó¡£
Debug.Print "¸Ã¿Ø¼þÕýÔÚ½â³ýÓëÖ÷»úµÄÁ¬½Ó¡£"
Case icDisconnected '¸Ã¿Ø¼þÒѳɹ¦µØÓëÖ÷»ú½â³ýÁËÁ¬½Ó¡£
Debug.Print "¸Ã¿Ø¼þÒѳɹ¦µØÓëÖ÷»ú½â³ýÁËÁ¬½Ó¡£"
Case icError 'ÓëÖ÷»úͨѶʱ³öÏÖÁË´íÎó¡£
Debug.Print "ÓëÖ÷»úͨѶʱ³öÏÖÁË´íÎó¡£"
Case icResponseCompleted '¸ÃÇëÇóÒѾ­Íê³É£¬²¢ÇÒËùÓÐÊý¾Ý¾ùÒѽÓÊÕµ½¡£
Debug.Print "¸ÃÇëÇóÒѾ­Íê³É£¬²¢ÇÒËùÓÐÊý¾Ý¾ùÒѽÓÊÕµ½¡£"
Open txtFile.Text For Binary Access Write As #1
Buff = InetHttp.GetChunk(1024, icByteArray)
Do While UBound(Buff) > 0
Put #1, , Buff()
Buff = InetHttp.GetChunk(1024, icByteArray)
'Put #1, , Buff
Loop
Put #1, , Buff
Close #1
'InetHttp.Cancel
'txtContent.Text = Content
End Select
End Sub
Option ExplicitPrivate Sub Form_Load()
txtFile.Text = App.Path & "\172362.jpg"
txtUrl.Text = "http://61.177.95.230/upload/opus/20051115/172362.jpg"
txtReferer.Text = "http://dpshow.163.com/showopus.php?opus_id=47309"
End SubPrivate Sub Command1_Click()
Dim strUrl As String '链接
Dim strReferer As String
Dim strHost As String '主机
Dim strCookie As String 'cookie
Dim intPost As Integer
Dim strHead As String '头
'重新构造请求头
strUrl = txtUrl.Text
strReferer = txtReferer.Text
If LCase(Left(strUrl, 7)) <> "http://" Then strUrl = "http://" & strUrl
intPost = InStr(8, strUrl, "/")
If intPost > 0 Then
strHost = Mid(strUrl, 8, intPost - 8)
strUrl = Right(strUrl, Len(strUrl) - intPost)
Else
strHost = Mid(strUrl, 8, Len(strUrl) - 8)
End If
' strHead = "GET " & strUrl & " HTTP/1.0" & vbCrLf
' & "Host: " & strHost & vbCrLf
strHead = "Accept: */*" & vbCrLf _
& "Referer: " & strReferer & vbCrLf _
& "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Maxthon; .NET CLR 1.1.4322)" & vbCrLf _
& "Pragma: no-cache" & vbCrLf _
& "Cache-Control: no-cache"
' & vbCrLf _
' & "Connection: close" & vbCrLf
Debug.Print strHead
InetHttp.Execute txtUrl.Text, "Get", "", strHead
End Sub
Private Sub InetHttp_StateChanged(ByVal State As Integer)
Dim Buff() As Byte
Select Case State
Case icNone '无状态可报告。
Debug.Print "无状态可报告。"
Case icResolvingHost '该控件正在查询所指定的主机的 IP 地址。
Debug.Print "该控件正在查询所指定的主机的 IP 地址。"
Case icHostResolved '该控件已成功地找到所指定的主机的 IP 地址。
Debug.Print "该控件已成功地找到所指定的主机的 IP 地址。"
Case icConnecting '该控件正在与主机连接。
Debug.Print "该控件正在与主机连接。"
Case icConnected '该控件已与主机连接成功。
Debug.Print "该控件已与主机连接成功。"
Case icRequesting '该控件正在向主机发送请求。
Debug.Print "该控件正在向主机发送请求。"
Case icRequestSent '该控件发送请求已成功。
Debug.Print "该控件发送请求已成功。"
Case icReceivingResponse '该控件正在接收主机的响应。
Debug.Print "该控件正在接收主机的响应。"
Case icResponseReceived '该控件已成功地接收到主机的响应。
Debug.Print "该控件已成功地接收到主机的响应。"
Case icDisconnecting '该控件正在解除与主机的连接。
Debug.Print "该控件正在解除与主机的连接。"
Case icDisconnected '该控件已成功地与主机解除了连接。
Debug.Print "该控件已成功地与主机解除了连接。"
Case icError '与主机通讯时出现了错误。
Debug.Print "与主机通讯时出现了错误。"
Case icResponseCompleted '该请求已经完成,并且所有数据均已接收到。
Debug.Print "该请求已经完成,并且所有数据均已接收到。"
Open txtFile.Text For Binary Access Write As #1
Buff = InetHttp.GetChunk(1024, icByteArray)
Do While UBound(Buff) > 0
Put #1, , Buff()
Buff = InetHttp.GetChunk(1024, icByteArray)
'Put #1, , Buff
Loop
Put #1, , Buff
Close #1
'InetHttp.Cancel
'txtContent.Text = Content
End Select
End Sub