Method 1: Read the XML content from the remote server to dataset. At the beginning, the data is read directly using the readxml (URL) method of dataset. The error "407 requiring proxy authentication" always occurs and is used in Program Global Proxy can be declared in.
Proxy
1 Dim Proxy As System. net. WebProxy = New System. net. WebProxy ( " 61.144.254.101: 80 " )
2 ' Proxy. Credentials = new system. net. networkcredential ("micheng", "123456789 ")
3
4 System. net. globalproxyselection. Select = Proxy
Method 2: Use the readxml (Io. Stream) method in dataset to read data to dataset.
Imports system. net
Getpagestring
1 Public Shared Function getpagestring () Function Getpagestring ( Byval URL As String , Byref Postmethod As String , Byref Cookies As Cookiecollection, Byval WP As WebProxy, Optional Byref Enctype As String = " Gb2312 " , Optional Byref Refer As String = "" ) As String
2
3 Dim Streamdata As Stream
4
5 If (URL. startswith ( " Http :// " ) = False ) Then
6 URL = " Http :// " & URL
7 End If
8
9 Dim Hrqst As Httpwebrequest = Httpwebrequest. Create (URL)
10
11 If Cookies Isnot Nothing Then
12 Hrqst. cookiecontainer = New Cookiecontainer
13 Hrqst. cookiecontainer. Add (cookies)
14 End If
15
16 Hrqst. contenttype = " Application/X-WWW-form-urlencoded "
17 Hrqst. headers. Add ( " Accept-Language " , " Zh-CN " )
18
19 If WP Isnot Nothing Then
20 Hrqst. Proxy = WP
21 End If
22
23 If String . Isnullorempty (postmethod) Then
24 Hrqst. Method = " Get "
25 Else
26 Hrqst. Method = Postmethod
27 End If
28
29 ' Dim Bt () as byte
30
31 Hrqst. allowautoredirect = True
32 ' Hrqst. allowwritestreambuffering = true
33 ' Bt = system. Text. encoding. ASCII. getbytes (postpara)
34 ' Hrqst. contentlength = Bt. Length
35 Hrqst. useragent = " Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) "
36 ' Hrqst. Referer = refer
37 ' Hrqst. keepalive = false
38 ' Hrqst. Timeout = 20000
39 ' Streamdata = hrqst. getrequeststream ()
40 ' Streamdata. Write (BT, 0, BT. length)
41 ' Streamdata. Close ()
42
43 Dim HRSP As Httpwebresponse
44 HRSP = Hrqst. getresponse ()
45 Streamdata = HRSP. getresponsestream
46 If Cookies Isnot Nothing And HRSP. Cookies Isnot Nothing Then
47 Cookies. Add (HRSP. Cookies)
48 End If
49
50 If (Enctype = "" ) Then
51 Enctype = " Gb2312 "
52 End If
53
54 Dim Readstream As New Io. streamreader (streamdata, system. Text. encoding. getencoding (enctype ))
55 Getpagestring = Readstream. readtoend ()
56 Streamdata. Close ()
57
58 End Function