Public Function GetCode(CodeBase, Url) '第一个参数是设置编码方式(GB2312或UTF-8)第二个参数是地址.Dim xmlHTTP1Set xmlHTTP1 = CreateObject("Microsoft.XMLHTTP")xmlHTTP1.Open "get", Url, TruexmlHTTP1.sendWhile xmlHTTP1.ReadyState <> 4DoEventsWendGetCode = xmlHTTP1.ResponseBodyIf CStr(GetCode) <> "" Then GetCode = BytesToBstr(GetCode, CodeBase)Set ObjXML = NothingEnd Function
Public Function BytesToBstr(strBody, CodeBase)Dim ObjStreamSet ObjStream = CreateObject("Adodb.Stream")With ObjStream.Type = 1.Mode = 3.Open.write strBody.Position = 0.Type = 2.Charset = CodeBaseBytesToBstr = .ReadText.CloseEnd WithSet ObjStream = NothingEnd Function
Private Sub Command1_Click() Dim aa As String aa = GetCode("GB2312", "http://www.2288822.net") RichTextBox1.Text = aaEnd Sub