无法将 httpwebrequest 与列表框一起使用
我面临着列表框的一个奇怪问题。我需要抓取 whois 信息。我使用以下代码来获取 whois 查询的源代码。如果我使用文本框,效果很好。但我需要将其用于多个 url,因此需要使用 lixtbox 循环遍历 url 列表。不幸的是,当我使用 listbox1.selecteditem 或 listbox1.text 时,它不起作用。但同样的代码也适用于网络浏览器。
请帮我解决这个问题
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://www.networksolutions.com/whois/results.jsp?domain=" & listbox1.selecteditem)
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)"
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim html As String = sr.ReadToEnd()
sr.Close()
谢谢
I am facing a strange problem with listbox. I need to scrab whois information. I used the following code to get source code of the whois query. It works fine if I use a textbox. But I need to use this for multiple url and therefore need to use lixtbox to loop through url list. Unfortunately when I use listbox1.selecteditem or listbox1.text it does not work. But this same code works with webbrowser.
Please help me solving this problem
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://www.networksolutions.com/whois/results.jsp?domain=" & listbox1.selecteditem)
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)"
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim html As String = sr.ReadToEnd()
sr.Close()
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生这种情况可能是因为您在处理下一个响应之前没有处理上一个响应。
您的代码应如下所示:
-- Pavel
This is probably happens because you don't dispose the previous response before processing the next one.
Your code should look like this:
-- Pavel