使用 C# 从 Sharepoint 使用 link 时出错((401)未授权)
Error when use link from Sharepoint with C# ( (401) unauthorized )
当我上传图片时,sharepoint 会给出与该图片对应的 link。
我正在做一个分析图像的C#项目,想用到SHarepoint的图像link。
但是在执行从WebClient的url()加载图片的函数时,被错误拦截了
错误名称:“远程服务器返回错误 (401) 未经授权”
这是我的 Sharepoint 中的图像显示 link(我正在扫描的 link):https://ibb.co/g9jYHKC
这是我使用的 webclient() 代码:
var webClient = new WebClient();
byte[] imageBytes = webClient.DownloadData("http://pmssd78/Animal/birddd.jpg"); //link copy from sharepoint like image show
期待大家的回音,谢谢
HTTP 401 表示未经授权,这意味着您未通过向其发出请求的资源进行身份验证。您需要通过服务器身份验证才能接受您的请求。
与 WebClient
class, you can do this via the Credentials
class 成员:
//Create a Credential Cache - you'll want this to be defined somewhere appropriate,
//maybe at a global level so other parts of your application can access it
CredentialCache credentialCache = new CredentialCache();
credentialCache.Add(new Uri("http://yourSharepointUrl.com"), "Basic", new NetworkCredential("yourUserName", "yourSecuredPassword"));
//Create WebClient, set credentials, perform download
WebClient webClient = new WebClient();
webClient.Credentials = credentialCache.GetCredential(new Uri("http://yourSharepoint.com"),
"Basic");
byte[] imageBytes = webClient.DownloadData("http://pmssd78/Animal/birddd.jpg");
凭证缓存中使用的 Uri
可能与 .DownloadData
签名中使用的 URI 类似。
当我上传图片时,sharepoint 会给出与该图片对应的 link。
我正在做一个分析图像的C#项目,想用到SHarepoint的图像link。
但是在执行从WebClient的url()加载图片的函数时,被错误拦截了
错误名称:“远程服务器返回错误 (401) 未经授权”
这是我的 Sharepoint 中的图像显示 link(我正在扫描的 link):https://ibb.co/g9jYHKC
这是我使用的 webclient() 代码:
var webClient = new WebClient();
byte[] imageBytes = webClient.DownloadData("http://pmssd78/Animal/birddd.jpg"); //link copy from sharepoint like image show
期待大家的回音,谢谢
HTTP 401 表示未经授权,这意味着您未通过向其发出请求的资源进行身份验证。您需要通过服务器身份验证才能接受您的请求。
与 WebClient
class, you can do this via the Credentials
class 成员:
//Create a Credential Cache - you'll want this to be defined somewhere appropriate,
//maybe at a global level so other parts of your application can access it
CredentialCache credentialCache = new CredentialCache();
credentialCache.Add(new Uri("http://yourSharepointUrl.com"), "Basic", new NetworkCredential("yourUserName", "yourSecuredPassword"));
//Create WebClient, set credentials, perform download
WebClient webClient = new WebClient();
webClient.Credentials = credentialCache.GetCredential(new Uri("http://yourSharepoint.com"),
"Basic");
byte[] imageBytes = webClient.DownloadData("http://pmssd78/Animal/birddd.jpg");
凭证缓存中使用的 Uri
可能与 .DownloadData
签名中使用的 URI 类似。