2013-02-28 94 views
1

我正在使用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失败相同。 有什么建议吗?

回答

2

看起来像某人有同样的问题。最近的这个提交将auth-scheme从“basic”改为“Basic”。 https://github.com/ServiceStack/ServiceStack/commit/d4f21c5355ab87d7315e142372eef9a40e096b5f 你应该可以更新你的dll。

根据RFC 2617 sec 1.2,认证方案是不区分大小写的。 见http://tools.ietf.org/html/rfc1945#page-47。我很好奇为什么供应商服务不接受它。

+0

太好了。我将再次拉出并测试。感谢您指出了这一点。我试图搜索Githud以查找设置它的代码,但无法找到它。 – brian 2013-02-28 15:58:28

+0

我已经运行3个月前上传的ServiceStack-v3.9.32。该修复是在一个月前提出的。什么时候上传新的软件包?我宁愿使用打包版本,也不愿意构建一个补丁程序来使其工作。 – brian 2013-02-28 21:42:53

+0

不知道的版本中,你就必须跟@mythz – kampsj 2013-02-28 22:11:04