远程服务器返回错误:(401)未经授权 [英] The remote server returned an error: (401) Unauthorized

查看:319
本文介绍了远程服务器返回错误:(401)未经授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这个code:

 字符串_response = NULL;
字符串_auth =基本法;
乌里_uri =新的URI(HTTP://my.domain.local/my-page.aspx);
HttpWebRequest的_REQ =(System.Net.HttpWebRequest)WebRequest.Create(http://api.olr.com/Service.svc);
CredentialCache _cc =新CredentialCache();
HttpWebResponse _res =默认(HttpWebResponse);
StreamReader的_sr =默认(StreamReader的);

_cc.Add(_uri,_auth,新的NetworkCredential(用户名,密码,TTP://api.olr.com/Service.svc));
_REQ preAuthenticate = TRUE。
_req.Credentials = _cc.GetCredential(_uri,_auth);
变种响应= _req.GetResponse();

就是System.IO.StreamReader SR =
                新就是System.IO.StreamReader(_res.GetResponseStream());

// _ SR =新的StreamReader(_res.GetResponseStream);
_response = _sr.ReadToEnd();
_sr.Close();
 

但得到:

  

远程服务器返回错误:(401)未经授权

  VAR响应= _req.GetResponse();
 

解决方案

你错过了'H'http://api.olr.com/Service.svc

  _cc.Add(_uri,_auth,新的NetworkCredential(用户名,密码,TTP://api.olr.com/Service.svc));
 

和还建立WebProxy

  System.Net.WebProxy代理=新WebProxy(http://api.olr.com,真正的);
proxy.Credentials =新的NetworkCredential(白金,01CFE4BF-11BA,http://api.olr.com/Service.svc);
_req.Proxy =代理;
 

I have written this code:

string _response = null;
string _auth = "Basic";
Uri _uri = new Uri("http://my.domain.local/my-page.aspx");
HttpWebRequest _req = (System.Net.HttpWebRequest)WebRequest.Create("http://api.olr.com/Service.svc");
CredentialCache _cc = new CredentialCache();
HttpWebResponse _res = default(HttpWebResponse);
StreamReader _sr = default(StreamReader);

_cc.Add(_uri, _auth, new NetworkCredential("username", "password", "ttp://api.olr.com/Service.svc"));
_req.PreAuthenticate = true;
_req.Credentials = _cc.GetCredential(_uri, _auth);
var response = _req.GetResponse();

System.IO.StreamReader sr =
                new System.IO.StreamReader(_res.GetResponseStream());

//_sr = new StreamReader(_res.GetResponseStream);
_response = _sr.ReadToEnd();
_sr.Close();

but getting:

The remote server returned an error: (401) Unauthorized.

at

var response = _req.GetResponse();

解决方案

you missed 'h' in "http://api.olr.com/Service.svc"

 _cc.Add(_uri, _auth, new NetworkCredential("username", "password", "ttp://api.olr.com/Service.svc"));

and also set WebProxy

System.Net.WebProxy proxy = new WebProxy("http://api.olr.com", true);
proxy.Credentials = new NetworkCredential("platinum", "01CFE4BF-11BA", "http://api.olr.com/Service.svc");
_req.Proxy = proxy;

这篇关于远程服务器返回错误:(401)未经授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆