我正在使用JsonServiceClient客户端与外部供应商在IIS 7上托管的RESTful服务交谈。ServiceStack JsonServiceClient发送基本代替Basic的授权标头
以下是我用来调用其Get方法的一些示例代码。
ServiceStack.ServiceClient.Web.JsonServiceClient client = new ServiceStack.ServiceClient.Web.JsonServiceClient("UrlToVendor"));
client.SetCredentials("userName", "password");
client.AlwaysSendBasicAuthHeader = true;
DTOReturn result = client.Get<DTOReturn>(string.Empty);
我总是得到授权失败。我们把一个嗅探器和授权头被发送为:密码
代替
基本用户名::
基本用户名密码
我们能够使用标准的.Net来电使其起作用
System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create( "UrlToVendor"); string authInfo = "userName:password"; authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo)); req.Accept = "application/json"; //text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 req.PreAuthenticate = true; req.Method = "GET"; req.Headers["Authorization"] = string.Format("Basic {0}", authInfo); System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
如果我们将“Basic”更改为“basic”,则这些标准调用与JasonServiceClient失败相同。 有什么建议吗?
太好了。我将再次拉出并测试。感谢您指出了这一点。我试图搜索Githud以查找设置它的代码,但无法找到它。 – brian 2013-02-28 15:58:28
我已经运行3个月前上传的ServiceStack-v3.9.32。该修复是在一个月前提出的。什么时候上传新的软件包?我宁愿使用打包版本,也不愿意构建一个补丁程序来使其工作。 – brian 2013-02-28 21:42:53
不知道的版本中,你就必须跟@mythz – kampsj 2013-02-28 22:11:04