gpt4 book ai didi

asp.net - 错误 :The remote server returned an error: (401) Unauthorized

转载 作者:行者123 更新时间:2023-12-03 11:34:56 25 4
gpt4 key购买 nike

我想获取互联网图片并插入到 word 中。

我用这个代码。

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;

最佳答案

我为 HttpWebRequest 添加凭据.

myReq.UseDefaultCredentials = true;
myReq.PreAuthenticate = true;
myReq.Credentials = CredentialCache.DefaultCredentials;

关于asp.net - 错误 :The remote server returned an error: (401) Unauthorized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10205854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com