1

所以我正在尝试从 url 路径下载图像。我正在使用以下经过测试并且可以正常工作的代码:

Client.DownloadFile("URL","FILE LOCATION")
Client.Dispose()

我使用的 url 是提供静态 jpg 图像的相机的 IP 地址。但问题是您第一次访问该网址时,它会要求您在启动页面上选择一种语言。如果您选择了一种语言,或者只是再次尝试该 url,它将带您到带有 jpg 的正确 url,并且将来任何时候都会完全绕过这个“语言启动屏幕”。所以问题是如何让我的代码在下载图像之前刷新/重新启动 url?

更新:所以网站确实创建了一个 cookie。这是我能够从谷歌浏览器中提取的内容:

Name:   LANGUAGE
Content:    0
Domain: xxx.xxx.xx.xxx
Path:   /cgi-bin
Send for:   Any kind of connection
Accessible to script:   Yes
Created:    Friday, May 24, 2013 8:27:05 AM
Expires:    When the browsing session ends
4

2 回答 2

2

也许该页面会创建一个具有默认语言的 cookie。尝试将 GET/POST 与 cookie 容器一起使用。

Dim logincookie As CookieContainer 'You can use this CookieContainer to do another request.


        Dim postData As String = ""
        Dim url as String = "yourUrl"
        Dim tempCookies As New CookieContainer
        Dim encoding As New UTF8Encoding
        Dim byteData As Byte() = encoding.GetBytes(postData)

        Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
        postReq.Method = "POST" 'GET or POST
        postReq.KeepAlive = True
        postReq.CookieContainer = tempCookies
        postReq.ContentType = "application/x-www-form-urlencoded"
        postReq.Referer = url
        postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
        postReq.ContentLength = byteData.Length

        Dim postreqstream As Stream = postReq.GetRequestStream()
        postreqstream.Write(byteData, 0, byteData.Length)
        postreqstream.Close()
        Dim postresponse As HttpWebResponse

        postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
        tempCookies.Add(postresponse.Cookies)
        logincookie = tempCookies
        Dim postreqreader As New StreamReader(postresponse.GetResponseStream())

        Dim thepage As String = postreqreader.ReadToEnd

        msgbox(thepage)
于 2013-05-24T12:47:49.807 回答
1

当然,根据您拥有的相机型号,您必须使用复杂的 URL 直接访问图像。
我有 FOSCAM 兼容的相机,完整的 URL 看起来像

http:_//_username:password@ip address/snapshot.cgi

这让我直接看到图像,没有启动画面或任何东西。你的相机品牌和型号是什么?

于 2013-05-24T12:39:46.953 回答