谢谢回复,不过我的情况与这不一样,我这是验证码图片,没有URL,是发出请求后服务器传输回来图片的BASE64编码和图片ID等信息,不是每次请求都能成功。有时抓包软件中看到图片的完整信息发过来了,但StreamReader没读取出来(一般是包比较大的时候),读出结果只是一两个乱码符号。不知是超时造成的(没有设置timeout),还是工具问题,别人写的程序没有这个问题。这是正常获取的数据格式:
{"Id":"6755f160-42cf-439f-a8ab-144c0d72034a","ImageByte":"/9j/4AAQSkZJRgABAQAAAQABAAD//gAiNjUzZjk5MzgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wAARCAA1AIIDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5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aedSgye+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编辑过]