从HTTPS URL获取图像并将其显示在图片框中

时间:2018-04-08 04:21:10

标签: vb.net

我想获取验证码图像并将其显示在此URL的图片框中:

https://ticket.urbtix.hk/internet/en_US/login/memberLogin

但网站需要Cookie才能访问图片的源网址而且这是一个 HTTPS 网址,我尝试了http请求来获取图片,但它并没有&# 39;工作它什么也不返回。

我正在使用RestSharp但它没有工作,它什么也没有返回。

Dim client = New RestClient(captcha_url)
            client.CookieContainer = New System.Net.CookieContainer()

            Dim cookie = client.CookieContainer.GetCookieHeader(New Uri("http://www.urbtix.hk/"))

            Dim request = New RestRequest("#", Method.GET)
            Dim response = client.Execute(request)


            Dim fileBytes = client.DownloadData(New RestRequest("#", Method.GET))


            PictureBox1.Image = New Bitmap(New MemoryStream(fileBytes))

1 个答案:

答案 0 :(得分:-1)

将此行添加到“ Dim client = ...”之前的代码中

        ServicePointManager.SecurityProtocol = CType((&HC0 Or &H300 Or &HC00), System.Net.SecurityProtocolType)

然后再次测试。