Tôi muốn có hình ảnh của internet và chèn vào từ.Lỗi: Máy chủ từ xa trả về lỗi: (401) Không được phép
Tôi sử dụng mã này.
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();
Tôi gặp lỗi trong myReq.GetResponse();
Lỗi: Máy chủ từ xa trả về lỗi: (401) Không được phép.
Chỉnh sửa công việc
Mã này đối với tôi :)
myReq.UseDefaultCredentials = true;
myReq.PreAuthenticate = true;
myReq.Credentials = CredentialCache.DefaultCredentials;
Cảm ơn, tôi sử dụng mã này, nhưng nhận được lỗi một lần nữa :( –
Bạn đã thay đổi nó cho một tên người dùng và mật khẩu mà thực sự có thể truy cập vào trang web của bạn? – Dante
Vâng, tôi thay đổi nó. –