ar.*_*gin 22 asp.net sharepoint sharepoint-2010
我想得到互联网的图片并插入到单词中.
我用这个代码.
MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart;
System.Net.WebRequest request = 
    System.Net.HttpWebRequest.Create("http://spsdev2:1009");
System.Net.WebResponse response = request.GetResponse();
ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
//Send an HTTP request and get the image at the URL as an HTTP response
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(fileName);
WebResponse myResp = myReq.GetResponse();
//Get a stream from the webresponse
Stream stream = myResp.GetResponseStream();
我在myReq.GetResponse()中收到错误;
错误:远程服务器返回错误:(401)未经授权.
编辑
这段代码对我有用:)
myReq.UseDefaultCredentials = true;
myReq.PreAuthenticate = true;
myReq.Credentials = CredentialCache.DefaultCredentials;
ar.*_*gin 36
我添加了凭据HttpWebRequest.
myReq.UseDefaultCredentials = true;
myReq.PreAuthenticate = true;
myReq.Credentials = CredentialCache.DefaultCredentials;
您不应该为您的网站提供凭据,而不是传递DefaultCredentials吗?
就像是 request.Credentials = new NetworkCredential("UserName", "PassWord");
另外,删除 request.UseDefaultCredentials = true; request.PreAuthenticate = true;
| 归档时间: | 
 | 
| 查看次数: | 84962 次 | 
| 最近记录: |