今天有空,研究了一下,需要这样写代码,测试可行。
Dim msg As String = ""
Dim req As System.Net.HttpWebRequest = System.Net.WebRequest.Create("http://www.shozaioh.com/member_login?email=qlc%40qlc.jp&passwd=qianqian&cmd=login")
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
req.ContentLength = msg.Length
Dim cookieCon As new System.Net.CookieContainer()
req.CookieContainer = cookieCon
Dim pos As System.Net.WebResponse = req.GetResponse()
Dim cookieheader As String = req.CookieContainer.GetCookieHeader(new Uri("http://www.shozaioh.com/"))
msgbox(cookieheader )
msg = ""
req = System.Net.WebRequest.Create("http://www.shozaioh.com/csv_download?cmd=yahoo&format_id=21")
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
req.ContentLength = msg.Length
cookieCon = new System.Net.CookieContainer()
req.CookieContainer = cookieCon
req.CookieContainer.SetCookies(new Uri("http://www.shozaioh.com/"), cookieheader)
'Dim postBytes() As Byte = Encoding.UTF8.GetBytes(msg)
'Dim requestStream As Object = req.GetRequestStream()
'requestStream.Write(postBytes, 0, postBytes.Length)
'requestStream.Close()
msgbox("开始获取,需要等候一段时间,确定?")
pos = req.GetResponse()
Dim stream As Object = pos.GetResponseStream
Dim buffer(1024) As Byte
Dim fileStream As new System.IO.FileStream("d:\test.csv", System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite)
Dim count As Integer = stream.Read(buffer, 0, buffer.Length)
Do While count <> 0
buffer.Initialize
fileStream.Write(buffer, 0, buffer.Length)
fileStream.Flush()
count = stream.Read(buffer, 0, buffer.Length)
Loop
fileStream.Close()
stream.Close()
pos.Close
msgbox("下载成功")
[此贴子已经被作者于2014-8-10 13:49:16编辑过]