首页 \ 问答 \ 解析WwwAuthenticate挑战字符串(Parse WwwAuthenticate challenge string)

解析WwwAuthenticate挑战字符串(Parse WwwAuthenticate challenge string)

我正在使用.NET Core 2.0为客户端提供RESTful服务。 远程服务返回这样的挑战:

WwwAuthenticate: Bearer realm="https://somesite/auth",service="some site",scope="some scope"

哪些需要变成令牌请求,如:

GET https://somesite/auth?service=some%20site&scope=some%20scope

使用AuthenticationHeaderValue解析头文件以获取方案和参数很容易,但这只是让我的realm="https://somesite/auth",service="some site",scope="some scope"字符串。 我如何轻松可靠地将其解析为单个realmservicescope组件? 这不是JSON,所以用NewtonSoft JsonConvert反序列化它将不起作用。 我可以将它转换成XML或JSON格式,但这看起来非常难以置信(更不用说不可靠)。

当然有更好的方法?


I am working on a client for a RESTful service, using .NET Core 2.0. The remote service returns challenges like this:

WwwAuthenticate: Bearer realm="https://somesite/auth",service="some site",scope="some scope"

Which need to get turned into token requests like:

GET https://somesite/auth?service=some%20site&scope=some%20scope

Parsing the header to get a scheme and parameter is easy with AuthenticationHeaderValue, but that just gets me the realm="https://somesite/auth",service="some site",scope="some scope" string. How can I easily and reliably parse this to the individual realm, service, and scope components? It's not quite JSON, so deserializing it with NewtonSoft JsonConvert won't work. I could regex it into something that looks like XML or JSON, but that seems incredibly hacky (not to mention unreliable).

Surely there's a better way?


原文:https://stackoverflow.com/questions/49417057
更新时间:2024-02-12 14:02

最满意答案

document.getElementById(gender).prop('checked',true); ,你正试图在一个简单的元素上使用JQuery函数。 所以你可以使用checked属性

document.getElementById(gender).checked = true;

或者使用JQuery

$(`#${gender}`).prop('checked', true)

In document.getElementById(gender).prop('checked',true);, you are trying to use a JQuery function on an simple element. So you can use either use the checked attribute

document.getElementById(gender).checked = true;

Or use JQuery

$(`#${gender}`).prop('checked', true)

相关问答

更多
  • 我认为你应该首先对所有单选按钮进行循环,检查每个按钮并将类附加到其父级: $("input:radio").each(function(){ if($(this).is(":checked")) { $(this).parent().addClass("panel-active"); } } I think you should make a loop of all radio buttons first, to check each one and append the ...
  • 从JQuery的角度来看,代码似乎并不那么混乱,但我建议你改变HTML结构。 通过部分ID匹配输入组需要脚本进行替换和连接以收集输入。 使用数据属性,脚本可以更轻松地收集值。 例如,您可以使用data-input-group="chart-group-"或您选择的任何属性标记属于一个组data-input-group="chart-group-" 。 那么所有适当的输入都可以从JQuery中简单地选择: $('input[type="radio"][data-input-group="cha ...
  • 1
    2
    3