| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5141 人关注过本帖
标题:服务器大图片不能获取
只看楼主 加入收藏
guchew
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2016-5-14
结帖率:28.57%
收藏
已结贴  问题点数:10 回复次数:7 
服务器大图片不能获取
我向一个服务器取图片,读取完成后再取下一张,服务器返回的是图片的BASE64编码。当图片尺寸较小时,可以正常接收到。但尺寸较大时,Responsetext不能获得正确数据,而抓包工具显示服务器返回的图片数据是完整的。没有设置Timeout。部分代码如下:
           With http
                .open("GET", URL, True)
                .SetRequestHeader("Cookie", sessionid)
                .setRequestHeader("Accept", "text/json")
                .setRequestHeader("Accept-Encoding", "deflate")
                .setRequestHeader("Connection", "Keep-Alive")
                .setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
                .send()
                .waitforresponse()
                If .Status = 200 Then
                    quma = .Responsetext
                If InStr(quma, "ImageByte") > 0 Then
                    '读取图片
                else
                     '执行下一次请求
                end if
                ......
怎样能让较大的图片也接收到?
搜索更多相关主题的帖子: 服务器 Cookie 图片 
2016-05-21 22:18
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:0 
程序代码:
    Private Function GetPhotoInfo(ByVal sPhotoUrl As String) As Image
        Try
            Dim mUri As New Uri(sPhotoUrl)
            Dim mRequest As HttpWebRequest = DirectCast(WebRequest.Create(mUri), HttpWebRequest)
            mRequest.Method = "GET"
            mRequest.Timeout = 200
            mRequest.ContentType = "text/html;charset=utf-8"
            Dim mResponse As HttpWebResponse = DirectCast(mRequest.GetResponse(), HttpWebResponse)
            Dim mStream As Stream = mResponse.GetResponseStream()
            Dim img As Image = Image.FromStream(mStream)
            mStream.Close()
            Return img
        Catch e As Exception
            MessageBox.Show(sPhotoUrl & "获取失败")
            Return Nothing
        End Try
    End Function
'示例:PictureBox1.Image = GetPhotoInfo("http://y0.)


===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2016-05-23 20:10
guchew
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2016-5-14
收藏
得分:0 
谢谢回复,不过我的情况与这不一样,我这是验证码图片,没有URL,是发出请求后服务器传输回来图片的BASE64编码和图片ID等信息,不是每次请求都能成功。有时抓包软件中看到图片的完整信息发过来了,但StreamReader没读取出来(一般是包比较大的时候),读出结果只是一两个乱码符号。不知是超时造成的(没有设置timeout),还是工具问题,别人写的程序没有这个问题。这是正常获取的数据格式:
{"Id":"6755f160-42cf-439f-a8ab-144c0d72034a","ImageByte":"/9j/4AAQSkZJRgABAQAAAQABAAD//gAiNjUzZjk5MzgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wAARCAA1AIIDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHB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HptzHIoWW5LeVB/EcjA4/WtS1R47SFJTudUUMfUgc0GkJN6MmooooNAooooAKbJv8tvLAL4O0N0z2zTqKAM2zmNtG32qO586Rt7fuSwzgDjZkY49c1DJKy3slxbGRfNVVffaSnGM9MD3rYooM+R2tcy7eSVUaGyt5dzMWaedSgye+DyfyqK9tljW2swd73MwaVj1bHJP6Ctmsq+aSHVYZzBJMixFYxGufnJ5z6cAUEyjZal2+m+z2M8o42Rkj644rLsYMXlnb9rSHfJ/vt/k0+9uje2jQKognDKzRznA2g5PPcVcsoVtIZJp5EMkp3ySZ49sewFAP3peQmsyGPTJgvLyDy1HqW4qt4eQRxXSDos5AqO9uzIjX4TdbW3MYPHmMTjP0Gaj0vU9Msrcq98Hkdi7t5bDJP4UEuS9om2HiIM99ZxopZnWRQPqAKZ4qlEdnbW0ZO/dvGD0Cjr+tGpXujag0TPfFGizgiMnOfqKgtf8AhHreQSPdNM4OQXVsfligzm03JJrXzDTgLfVZJ4yWi84Q7nO4nI65+uK6muc0rS55bI/6Q0MMkpby2j5wDwQTyDxXRUGtFNRFooooNwooooAKKKKACiiigApKKKAIri1gugoniWQKcjcKrf2Np/mb/sy9c7cnbn/dziiiglxi90XQqhdoA29MU6iigoKKKKACiiigAooooAKKKKAP/9k=","ServerId":"8","TypeId":"2040","Score":"10","Multiple":"1","Time":"10000","Tip":"%e8%af%b7%e8%be%93%e5%85%a5%e5%af%b9%e5%ba%94%e7%9a%84%3cspan+style%3d%22color%3ared%22%3e4%3c%2fspan%3e%e4%bd%8d%3cspan+style%3d%22color%3ared%22%3e%e8%8b%b1%e6%96%87%e5%ad%97%e6%af%8d%3c%2fspan%3e","TopTip":"%e8%af%b7%e8%be%93%e5%85%a5%e5%af%b9%e5%ba%94%e7%9a%84%3cspan+style%3d%22color%3ared%22%3e4%3c%2fspan%3e%e4%bd%8d%3cspan+style%3d%22color%3ared%22%3e%e8%8b%b1%e6%96%87%e5%ad%97%e6%af%8d%3c%2fspan%3e","BottomTip":"%e7%ba%af%e8%8b%b1%e6%96%87%ef%bc%9a%e6%af%8f%e7%a0%81%3cspan+style%3d%22color%3ared%22%3e%40Score%3c%2fspan%3e%e5%88%86%ef%bc%8c%3cspan+style%3d%22color%3ared%22%3e%e8%b6%85%e6%97%b6%e5%8f%8c%e5%80%8d%e6%89%a3%e5%88%86%3c%2fspan%3e%e3%80%82","ResultRegexp":"XlthLXpBLVpdJA%3d%3d","Script":"","Script2":"","Length":"4"}
  "ImageByte":"后面有图片BASE64编码。这是我的程序代码:
  Dim encoding As ASCIIEncoding = New ASCIIEncoding()
  Dim myRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
        myRequest.Method = "GET"
        myRequest.ContentType = "application/x-www-form-urlencoded"
        myRequest.CookieContainer = cookie
        myRequest.Accept = "*/*"
        myRequest.KeepAlive = True
        Dim myResponse As HttpWebResponse = CType(myRequest.GetResponse(),     HttpWebResponse)
        Dim newStream As Stream = myResponse.GetResponseStream()
        Dim reader As StreamReader = New StreamReader(newStream,   System.Text.Encoding.GetEncoding("utf-8"))
        dim str as string = reader.ReadToEnd()
        TextBox1.Text = str
        reader.Close()
        newStream.Close()
        If InStr(str, "ImageByte") > 0 Then
        '读取图片
        ......

[此贴子已经被作者于2016-5-24 12:10编辑过]

2016-05-24 12:05
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:10 
是不是与你取位代码有关,我不能重现你的问题,所以无法帮你解决。
另外,你的BASE64还原函数有没有错误之处呢?
那个代码还原后的图片应当是这个图吧:
图片附件: 游客没有浏览图片的权限,请 登录注册

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2016-05-24 14:40
guchew
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2016-5-14
收藏
得分:0 
问题解决了,换其他的读取方式。
2016-05-24 19:09
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:0 
以下是引用guchew在2016-5-24 19:09:54的发言:

问题解决了,换其他的读取方式。


可否共享呢?也好让其他有同样需求的网友能分享与借鉴。

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2016-05-24 19:57
guchew
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2016-5-14
收藏
得分:0 
不想误导大家,其实也没真正解决,目前我只能判断出哪些图片不能接收到,通过代码进行异常处理。现在发现接收不了不是图片大小的问题,可能是格式问题。举个例子:能够读取出来的BASE64编码是这个样子:
"hUG/oPRT6uMAkwaNbS901MJZVofDaa/gvQGlzLg4qkY6Odi85qNYr4/vJWzNlYQvmzKAVgaqQAx2VgmACnii+yy1HJ/wRVClgYmqBRw6HG7zTJ3JekQRHDax9WYLM8gI2i9u57RQQeNKIkt0G9qFFV6QbYhji2KuMz2EAmcFHCUb9HGv919EaxXtVArcSG+R7VbMGoN7MDwPHXTEBGm7lk4WGH9yUNjS+RCnvlgZqGSQmlRorF6cybKiS/Moq3amkCBKiMnRFiscky08k3vUXmxQ+1qLB4....."
而不能接收到的是这个样子:
"Qk1eIwAAAAAAADYAAAAoAAAAZAAAAB4AAAABABgAAAAAACgjAAAAAAAAAAAAAAAAAAAAAAAA/////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////+Pr67/f29P//9v///f//8+7v//v8//v+y///2fTx//f///n///v///3+2/rz//////////......"
或者:
"Qk1eUQAAAAAAADYAAAAoAAAAggAAADUAAAABABgAAAAAAAAAAADEDgAAxA4AAAAAAAAAAAAA9vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb
29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb2....."
抓包工具能够抓到数据,那就是有办法取得这些数据的。如果大家知道方法请告知,谢谢。


[此贴子已经被作者于2016-5-25 15:28编辑过]

2016-05-25 13:39
guchew
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2016-5-14
收藏
得分:0 
谜底解开了,是抓包软件误导了我。返回数据是GZIP压缩了的。抓包软件没有显示这个信息,直接显示解压后的数据和数据长度。
2016-06-11 20:54
快速回复:服务器大图片不能获取
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022526 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved