Voglio ottenere un'immagine di Internet e inserirla in una parola.Errore: il server remoto ha restituito un errore: (401) Non autorizzato
Io uso questo codice.
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();
ottengo errore nel myReq.GetResponse();
Errore: il server remoto ha restituito un errore: (401) Non autorizzato.
Modifica lavoro
Questo codice per me :)
myReq.UseDefaultCredentials = true;
myReq.PreAuthenticate = true;
myReq.Credentials = CredentialCache.DefaultCredentials;
Grazie, io uso questo codice, ma ottiene ancora una volta l'errore :( –
Hai cambiato per un nome utente e una password che può effettivamente accedere al tuo sito? – Dante
Sì, lo cambio. –