PictureBox.Load方法从需要身份验证的网站添加图片

时间:2016-05-12 11:36:11

标签: c# .net

我想通过.Load()方法将图片添加到PictureBox。该图片的问题在于它停留在需要身份验证的网站上!

链接就像:https://intranet.company.com/_layouts/15/company/PortraitHandler.ashx?isinternal=true&account=test/account

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

解决这个问题:

public Bitmap getImageFromURL(string sURL)
    {
        HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(sURL);
        Request.Method = "GET";
        Request.UseDefaultCredentials = true;

        HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
        System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(Response.GetResponseStream());
        Response.Close();

        return bmp;
    }