带有 GET 的 HttpWebRequest:401 未经授权
我发现 httpWebRequest 有一些问题,我在其他论坛上阅读了所有相同的问题,但答案似乎不起作用。我的代码:
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse resp;
wr.ContentType = "text/html; charset=UTF-8";
wr.Method = "GET";
wr.Credentials = new NetworkCredential("user", "password");
resp = (HttpWebResponse)wr.GetResponse();
远程服务器返回错误:(401) 未经授权。
响应说 cookie 中没有身份验证令牌。我可以使用 POST 方法使用我的身份验证请求来接收此令牌。我什至尝试通过“new Cookie ("authToken",token_value)”将其放入CookieContainer。
但结果是相同的 - 错误401
。有人知道解决办法吗?
谢谢。
我使用 Zimbra Web 服务器,有权控制它。 .NET 4.0。我的 url 是我需要下载的 .eml 文件的路径。要指定文件,我需要添加一些 GET 参数:id 和部分。所以整个地址看起来像 http://someserver.info/service/content /get?id=1&part=1
I found some problem with httpWebRequest, I've read all the same issues on other forums, but answers don't seem to work. My code:
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse resp;
wr.ContentType = "text/html; charset=UTF-8";
wr.Method = "GET";
wr.Credentials = new NetworkCredential("user", "password");
resp = (HttpWebResponse)wr.GetResponse();
The remote server returned an error: (401) Unauthorized.
Response says there's no auth token in cookies. I can receieve this token using my auth request with POST method. I even tried to put it to CookieContainer by "new Cookie ("authToken",token_value)".
But the result is the same - error 401
. Does anybody know the solution?
Thanx.
I use Zimbra web server, have an access to control it. .NET 4.0. My url is the path to .eml file I need to download. To specify the file I need to add some GET parameters: id and part. So the whole address looks like http://someserver.info/service/content/get?id=1&part=1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(在OP的评论和问题编辑中回答。移至此处。请参阅问题没有答案,但问题在评论中解决(或在聊天中扩展))
OP 写道:
(Answered in the comments and question edits by OP. Moved here. See Question with no answers, but issue solved in the comments (or extended in chat) )
The OP wrote: