求助:VB转VB.NET 代码错误,求帮助
Dim SendStr As String = Nothing
Dim XMLObject As Object = CreateObject("Microsoft.XMLHTTP")
XMLObject.open("GET", "http://quotes.money.163.com/corp/1034/code=600221.html", False)
XMLObject.setRequestHeader("CONTENT-TYPE", "application/x-www-form-urlencoded")
XMLObject.Send(SendStr)
Dim HTMLStr As String = XMLObject.ResponseTEXT
Dim HTMLDoc As Object = CreateObject("htmlfile")
HTMLDoc.body.innerhtml = HTMLStr
最后一句 HTMLDoc.body.innerhtml = HTMLStr 在VB6下可以成功执行,但是在VS2010下,返回 “未设置对象变量或 With 块变量。”错误,本人菜鸟,求高手帮忙,怎么才能顺利执行?
[解决办法]
Dim url As String = "http://quotes.money.163.com/corp/1034/code=600221.html"
Dim httpReq As System.Net.HttpWebRequest
Dim httpResp As System.Net.HttpWebResponse
Dim httpURL As New System.Uri(url)
httpReq = CType(WebRequest.Create(httpURL), HttpWebRequest)
httpReq.Method = "GET"
httpResp = CType(httpReq.GetResponse(), HttpWebResponse)
httpReq.KeepAlive = False
Dim reader As StreamReader = New StreamReader(httpResp.GetResponseStream, System.Text.Encoding.Default)
Dim respHTML As String = reader.ReadToEnd() 'respHTML就是网页内容