Home > Software engineering >  Using VB to INET download data, large file download success, small file error, why?
Using VB to INET download data, large file download success, small file error, why?

Time:10-10

Inet control can download data files, large files can download success, small files are downloaded to a level of about 2 k error message file, how to return a responsibility? Please instruct
(1) Inet is OpenURL way,
 Dim (b) As Byte 
Dim strURL As String
Dim fil As Integer
On Error GoTo Err1

Label3. Caption="is being downloaded,,,,,"
'the url screen
StrURL="http://www.kinglmm.com.cn/data/UserSer.DAT" "small files, download content is not correct
'strURL="ftp://www.kinglmm.com.cn/data/cod21.add", "large files, correct download
(b)=rc.inet1. OpenURL (strURL, icByteArray)
If UBound (b) & gt; 0 Then
Fil=FreeFile
Open "D: \ UserSer dat" For Binary Access Write As # fil
'Open "D: \ cod21. Add" For Binary Access Write As # fil
Put # fil, and (b)
Close # fil
Label3. Caption="download"
The Else
Label3. Caption="to"

End the If
The Exit Sub

Err1:
MsgBox "download data error"

(2) using the Get method of Inet is the same:
 rc.inet1. URL="http://www.kinglmm.com.cn/data/UserSer.DAT" 
'rc.inet1. URL="http://www.kinglmm.com.cn/data/cod21.ADD"
Rc.inet1. Execute, "Get"

Private Sub Inet1_StateChanged (ByVal State As an Integer)
Dim aa As the Variant
Dim vtData () As Byte 'data variables,
Dim iU As Long, I As an Integer, il As Integer
Dim TotalLength As the Variant

If the State=12 Then

TotalLength=Val (rc.inet1 GetHeader (" the Content - length "))
PsB. Max=TotalLength
'Open "d: \ CodeAdd bin" For Binary Access Write As # 1
'the Open "d: \ UserSer Dat" For Binary Access Write As # 1
'Open "d: \ Cod21 bin" For Binary Access Write As # 1
Open "d: \ the UserINfo. TXT" For Binary Access Write As # 1
VtData=https://bbs.csdn.net/topics/Inet1.GetChunk (1024, icByteArray)
The Do While UBound (vtData) & gt; 0
DoEvents
Put # 1, and vtData
If (PsB) Value + 1024) & gt; PsB. Max Then
PsB. Value=https://bbs.csdn.net/topics/PsB.Max
The Else
PsB. Value=https://bbs.csdn.net/topics/PsB.Value + 1024
End the If
VtData=https://bbs.csdn.net/topics/Inet1.GetChunk (1024, icByteArray)
Loop
Put # 1, and vtData
Close # 1
MsgBox "the download
"End the If
If the State=11 Then 'error
End the If
End Sub


Small file download didn't say wrong, but the file downloaded a 2 k, is not the file on the site, is an error message file, save it into a TXT file, display content is:
 & lt; ! PUBLIC DOCTYPE HTML "- 4.01//////W3C DTD HTML EN" "http://www.w3.org/TR/html4/strict.dtd" & gt; 
Cannot find the page & lt;/TITLE> <br/><meta HTTP - EQUIV="content-type" Content="text/HTML. Charset=GB2312 "& gt; <br/><style type="text/CSS" & gt; <br/>BODY {9 pt/12 pt font: tahoma} <br/>H1 {12 pt font: 15 pt/song typeface} <br/>The H2 {9 pt/12 pt font: tahoma} <br/>A: the link {color: red} <br/>A: visited {color: maroon} <br/></style> <br/></HEAD> <body> <TABLE width=500 border=0 cellspacing=10 & gt; <TR> <TD> <br/><br/><H1 & gt; Cannot find the page & lt;/h1 & gt; <br/>The page you are looking for might have been deleted, renamed or is temporarily unavailable. <br/><Hr> <br/><p> Please try the following: & lt;/p> <br/><Ul> <br/><Li> Ensure that the browser's address bar shown in the website address spelling and format is correct, & lt;/li> <br/><Li> If you reached this page by clicking a link, please contact the site administrator and inform them of the link format is not correct, <br/></li> <br/><Li> Click & lt; A href="javascript: history. The back (1)" & gt; Back & lt;/a> Button to try another link, & lt;/li> <br/></ul> <br/><The h2 & gt; HTTP error 404 - file or directory, & lt; br> Internet information services (IIS) & lt;/h2 & gt; <br/><Hr> <br/><p> Technical information (for technical support personnel & lt;/p> <br/><Ul> <br/><Li> Go to & lt; A href="http://go.microsoft.com/fwlink/? Linkid=8180 "& gt; Microsoft product support services & lt;/a> And search including & amp; other HTTP& Throughout; And & amp; other 404 & amp; Throughout; The title, & lt;/li> <br/><Li> Open & amp; other IIS help & amp; Throughout; (access) in IIS manager (inetmgr), and then search the title for & amp; other Web site set up & amp; Throughout; , & amp; other Routine management tasks & amp; Throughout; And & amp; other About custom error messages & amp; Throughout; The theme of & lt;/li> <br/></ul> <br/><br/></TD> </TR> </TABLE> </BODY> </HTML> <br/></pre> <br/><br/><br/>Excuse me what reason be? <br/><br/><p class="article - content rp"> CodePudding user response: </p>'strURL="ftp://www.kinglmm.com.cn/data/cod21.add", "large files, correct download <br/>========<br/>Is not FTP, HTTP, this column is the way to debug the FTP, explain, don't tell me because this is how the FTP then can<p class="article - content rp"> CodePudding user response: </p>People don't "know" my feeling is that HTTP binary data file format, so can't download <br/>My two hexadecimal file format is editing the random file format, without using ADO database structure, such as HTTP recognition, is the reason?<p class="article - content rp"> CodePudding user response: </p>Really is a problem of HTTP binary recognition, have been solved </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/Softwareengineering/60523.html" target="_blank" style="color:#999">https//www.codepudding.com/Softwareengineering/60523.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/Softwareengineering/60522.html'>The graduation thesis can run directly warehouse management system software</a></div> <div class="detail-arr-right">Next:<a href='/Softwareengineering/60524.html'>Vb graphics problems</a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=Network+programming' target='_blank'>Network programming</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>