Foxtable(狐表)用户栏目专家坐堂 → 数据包下载问题


  共有4495人关注过本帖树形打印复制链接

主题:数据包下载问题

帅哥哟,离线,有人找我吗?
有点甜
  11楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/8/8 16:26:00 [只看该作者]

 分析了一下,可以做,但是比较麻烦,需要用代码构造一个头信息发送到这个url

 

 http://www.shozaioh.com/member_login?email=qlc%40qlc.jp&passwd=qianqian&cmd=login

 

 然后才能跳转到对应的下载目录。关键是跳转路径的头信息的设置,自己看着办吧。


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  12楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/8/8 16:30:00 [只看该作者]

 太麻烦,不想,也没时间帮你做。

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  13楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/8/10 13:47:00 [只看该作者]

今天有空,研究了一下,需要这样写代码,测试可行。

 

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编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  14楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/8/10 13:53:00 [只看该作者]

 代码精简一下,如下。

 

 

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 = "Get"
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 )


req = System.Net.WebRequest.Create("http://www.shozaioh.com/csv_download?cmd=yahoo&format_id=21")
req.Method = "Get"
cookieCon = new System.Net.CookieContainer()
req.CookieContainer = cookieCon
req.CookieContainer.SetCookies(new Uri("http://www.shozaioh.com/"), cookieheader)


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("下载成功")


 回到顶部
总数 14 上一页 1 2