【问题标题】:Getting 406 when using OpenRasta HTTPEntity as return response?使用 OpenRasta HTTPEntity 作为返回响应时得到 406?
【发布时间】:2011-10-26 00:23:58
【问题描述】:

在我的处理程序代码中,尝试使用必要的 openid 标头/正文返回重定向响应以执行用户代理重定向以进行身份​​验证,但是当我在操作结果中使用 HTTPEntity 设置返回响应时,我得到 406 Not Acceptable on客户端?那有什么问题?以下代码不完整,属于原型质量!

这是我的处理程序代码:

private static OpenIdRelyingParty openid = new OpenIdRelyingParty();
public OperationResult Get(string contentId)
{
   var response = openid.GetResponse();
   Identifier id;
   Identifier.TryParse("https://www.google.com/accounts/o8/id", out id);
   OutgoingWebResponse owr = openid.CreateRequest(id).RedirectingResponse;

   HttpEntity he = new HttpEntity(new HttpHeaderDictionary(owr.Headers), owr.ResponseStream);

   return new OperationResult.SeeOther { ResponseResource = he };

 }

【问题讨论】:

    标签: dotnetopenauth openrasta


    【解决方案1】:

    我们目前不支持 IMessage / IHttpEntity / IResponse 作为返回类型,所以这不起作用(但如果支持就好了,而且可能应该支持)。

    现在的问题是 IRequest / IResponse(和关联的实体主体)由托管环境控制。

    如果您希望它按原样工作,我建议创建一个自定义编解码器,将其注册到 IHttpEntity (ResourceSpace.Has.ResourcesOfType().WithoutUri.TranscodedBy()) 并使用该编解码器复制标头和现有 IResponse 上的正文,这应该带你 5 LOC。

    我在 https://github.com/openrasta/openrasta-core/issues/33 上打开了一个错误,以便我们可以将其移至核心。

    【讨论】:

    • 谢谢serialseb,我得到了它的一个例外,响应具有只读标头,因此无法设置标头,我们有什么办法可以做到这一点?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-22
    • 1970-01-01
    • 2019-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多