[英]VB 2010 - How to read an INI file that is on the internet without downloading it
I need to know how can I read an INI file that is on the internet without download it into the computer, can save it into memory, I need to do this with Visual Basic 2010. 我需要知道如何读取互联网上的INI文件而不将其下载到计算机中,可以将其保存到内存中,我需要使用Visual Basic 2010执行此操作。
I need to read all content and get every value from every section but without download the file, I've tried with this class: 我需要阅读所有内容并从每个部分获取每个值,但没有下载文件,我已经尝试过这个类:
Question: Read and write in INI file 问题:在INI文件中读写
But only works with computer-stored-files, not with files on internet, I've been thinking in get all content of the INI file and save it into a string, but the class doesn't read it at all, can anyone help me? 但只适用于计算机存储文件,而不是互联网上的文件,我一直在考虑获取INI文件的所有内容并将其保存到字符串中,但该类根本不读它,任何人都可以帮助我? Thanks in advanced.
提前致谢。
The best thing you can do is reading the file as a webpage (basically, this is what it is) and then parsing all the information you get. 您可以做的最好的事情是将文件作为网页读取(基本上就是这样),然后解析您获得的所有信息。 I have used the code below many times and works pretty well:
我已经多次使用下面的代码,效果很好:
Public Class Form1
Friend WithEvents webBrower0 As New WebBrowser
Friend WithEvents tabs As New TabControl
Friend WithEvents tabPage0 As New TabPage
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
startBrowser()
End Sub
Public Sub startBrowser()
Dim url As String = "http://..."
tabs.Controls.Add(tabPage0)
tabPage0.Controls.Add(webBrower0)
AddHandler webBrower0.Navigating, AddressOf WebBrowser_Navigating
AddHandler webBrower0.DocumentCompleted, AddressOf WebBrowser_DocumentCompleted
tabPage0.Refresh()
webBrower0.Navigate(url)
End Sub
Private Sub WebBrowser_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs)
End Sub
Private Sub WebBrowser_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
Dim source_string As String = webBrower0.DocumentText 'content of the file
End Sub
End Class
After reading everything, the string source_string
will be populated with the file content. 读完所有内容后,字符串
source_string
将填充文件内容。 It follows the html format but you shouldn't find any problem to extract the information you want. 它遵循html格式,但你不应该找到任何问题来提取你想要的信息。
If you can, the easiest way is to download the file to a temp location. 如果可以,最简单的方法是将文件下载到临时位置。 Use CreateTempFile to get a temp file name.
使用CreateTempFile获取临时文件名。
If you can't save the file at all, you can download it to memory with the following (untested): 如果您根本无法保存文件,可以使用以下(未经测试)将其下载到内存:
Dim request As HttpWebRequest
Dim response As HttpWebResponse
request = Net.HttpWebRequest.Create(url) ' url of the file
request.Method = "GET"
response = request.GetResponse()
Using reader As StreamReader = New StreamReader(response.GetResponseStream(), Encoding.Default)
Dim fileStr As String = reader.ReadToEnd() ' fileStr contains the contents of the file
End Using
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.