![](/img/trans.png)
[英]SharePoint 2019 Search REST API Is Returning 401 Unauthorized - When Called from C# Using Basic Authorization Request Header
[英]Error when use link from Sharepoint with C# ( (401) unauthorized )
当我上传图片时,sharepoint 会给出与该图片对应的链接。
我正在研究分析图像的 C # 项目,并希望使用 SHarepoint 的图像链接。
但是在执行function从WebClient的url()中加载图片时,我被一个错误阻止了。
错误名称:“远程服务器返回错误(401)未授权”
这是我的 Sharepoint 中的图片显示链接(我正在扫描的链接): 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,您可以通过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 类似。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.