如何判断响应流是否对在VB.NET中创建映像有效?

时间:2014-05-02 15:39:11

标签: vb.net image httpwebresponse

我正在使用VB.NET从Web服务器中提取图像,当我在工作站上调试时,一切正常。但是,当我将应用程序部署到我的服务器时,它失败了。它似乎无法从流中绘制图像,错误为“参数无效”,这发生在try catch块下面的GetImage行中。我知道可以在服务器上检索图像,因为如果我将URL放在浏览器地址栏中,图像显示就好了。如何对响应流进行故障排除以确定发生了什么?

Function GetImage(ByVal URL As String) As System.Drawing.Image
    Dim Request As System.Net.HttpWebRequest
    Dim Response As System.Net.HttpWebResponse
    GetImage = Nothing

    Try
        Request = System.Net.WebRequest.Create(URL)
        Response = CType(Request.GetResponse, System.Net.WebResponse)

        If Request.HaveResponse Then 
            If Response.StatusCode = Net.HttpStatusCode.OK Then 
               GetImage = System.Drawing.Image.FromStream(Response.GetResponseStream)
            End If
        End If
    Catch e As Exception
        txtActivity.Text = "Error retrieving image from URL " & URL & vbCrLf & e.ToString() & vbCrLf & txtActivity.Text
        Exit Try
    Finally

    End Try
End Function

0 个答案:

没有答案