等待httpclient(Awaiting httpclient)
这是代码 -
版本3:删除r.result但它仍然无法正常工作。
protected async void LogIn(LoginInfo _credentials) { HttpResponseMessage r = await DoLogin("demo", "Abc123$"); if (r.IsSuccessStatusCode) { AccountAccess aa = new AccountAccess(); var x = await r.Content.ReadAsStringAsync(); aa = JsonConvert.DeserializeObject<AccountAccess>(x); Application.Current.Properties["access_token"] = aa.access_token; } else //if (lr == LoginResult.LoginRes.NoAuth) { Alert("Alert", "Username/password combination is incorrect", "OK"); } } private async Task<HttpResponseMessage> DoLogin(string username, string password) { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(Constants.LOGINURL); var response = await client.PostAsync("Token", new StringContent("grant_type=password&username=" + username + "&password=" + password, Encoding.UTF8)); return response; }
等待调用以发布用户名和密码并获取令牌永远不会返回。
我做错了吗?
Here is the code -
VERSION 3: Remove r.result and it still doesn't work.
protected async void LogIn(LoginInfo _credentials) { HttpResponseMessage r = await DoLogin("demo", "Abc123$"); if (r.IsSuccessStatusCode) { AccountAccess aa = new AccountAccess(); var x = await r.Content.ReadAsStringAsync(); aa = JsonConvert.DeserializeObject<AccountAccess>(x); Application.Current.Properties["access_token"] = aa.access_token; } else //if (lr == LoginResult.LoginRes.NoAuth) { Alert("Alert", "Username/password combination is incorrect", "OK"); } } private async Task<HttpResponseMessage> DoLogin(string username, string password) { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(Constants.LOGINURL); var response = await client.PostAsync("Token", new StringContent("grant_type=password&username=" + username + "&password=" + password, Encoding.UTF8)); return response; }
The await call to post the username and password and get a token never returns.
Am I doing something incorrect?
原文:https://stackoverflow.com/questions/37077953
最满意答案
re='[[:space:]]GTX[[:space:]]1050[[:space:]]' [[ $test =~ $re ]]
......会做的。
\s
是PCRE语法。=~
仅保证POSIX ERE语法,因此PCRE扩展不可用。[[:space:]]
是符合POSIX的等价物。- 你不能引用正则表达式而不使它成为字面意思。 也就是说 - 如果你想将
re
的值作为正则表达式而不是要搜索的精确字符串,它必须是=~ $re
而不是=~ "$re"
。引用bash-hackers维基上的文档:
使用operator =〜,左侧操作数与右侧的扩展正则表达式(ERE)匹配。
这与模式匹配是一致的: 正则表达式的每个引用部分都是字面上的,即使它包含正则表达式特殊字符。
最佳做法是将正则表达式与变量匹配。 这是为了避免在其他有效的正则表达式上进行shell解析错误。
re='[[:space:]]GTX[[:space:]]1050[[:space:]]' [[ $test =~ $re ]]
...will do the trick.
\s
is PCRE syntax.=~
only guarantees POSIX ERE syntax, so PCRE extensions aren't available.[[:space:]]
is the POSIX-compliant equivalent.- You can't quote the regex without making it literal. That is to say -- it must be
=~ $re
and not=~ "$re"
if you want the value inre
to be treated as a regular expression rather than an exact string to search for.Quoting from the documentation on the bash-hackers wiki:
Using the operator =~, the left hand side operand is matched against the extended regular expression (ERE) on the right hand side.
This is consistent with matching against patterns: Every quoted part of the regular expression is taken literally, even if it contains regular expression special characters.
Best practice is to put the regular expression to match against into a variable. This is to avoid shell parsing errors on otherwise valid regular expressions.
相关问答
更多-
port="[^0-9]$s$" 您可以删除{print} ,顺便说一句,因为这是默认操作,所以您只需要: s=$1 port="[^0-9]$s$" netstat -numeric | awk -v pat="$port" '$6 == "ESTABLISHED" && $4 ~ pat' 你没有工作的原因是/.../是regexp常量分隔符,就像"..."是字符串常量分隔符所以将它们包含在动态正则表达式中就好像你在字符串中包含引号一样,例如foo="\"stuff\""而不是foo="stuff" ...
-
你可以做: for f in "$prefix"*; do # removes prefix part temp="${f#$prefix}" # removes everything after last _ and then adds back extension .mov mv "$f" "${temp%_*}.${temp##*.}" done You can do: for f in "$prefix"*; do # removes prefix part temp ...
-
帮助Bash脚本(Help with Bash script)[2024-02-11]
只需删除read line周围的[] - 它们应该用于执行测试(文件存在,字符串为空等)。 Just remove the [] around read line - they should be used to perform tests (file exists, string is empty etc.). -
如何在bash脚本中使用Perl正则表达式字符?(How can I use Perl regexp characters when inside a bash script?)[2022-04-16]
它不是bash变量,而是单引号bash字符串中的单引号。 It isn't the bash variable, it is the single quotes in your single quoted bash string. -
re='[[:space:]]GTX[[:space:]]1050[[:space:]]' [[ $test =~ $re ]] ......会做的。 \s是PCRE语法。 =~仅保证POSIX ERE语法,因此PCRE扩展不可用。 [[:space:]]是符合POSIX的等价物。 你不能引用正则表达式而不使它成为字面意思。 也就是说 - 如果你想将re的值作为正则表达式而不是要搜索的精确字符串,它必须是=~ $re而不是=~ "$re" 。 引用bash-hackers维基上的文档: 使用operato ...
-
Perl&Bash:FIND regexp(Perl & Bash : FIND regexp)[2021-06-21]
改变这一行: $tab=`find $dir -type f -name \"$dir_$adresse_$ip_*\"`; 同 $tab=`find $dir -type f -name \"${dir}_${adresse}_${ip}_*\"`; change this line: $tab=`find $dir -type f -name \"$dir_$adresse_$ip_*\"`; with $tab=`find $dir -type f -name \"${dir}_${adr ... -
需要改进bash regexp(need to improve bash regexp)[2022-04-11]
修改你的: \s*${varName}(\s?[\s\=]\s?).+\s*;{0,1} Modifying yours: \s*${varName}(\s?[\s\=]\s?).+\s*;{0,1} -
Java Script RegExp(Java Script RegExp)[2023-12-13]
如果您正在寻找特殊字符,请尝试\W var pattern = new RegExp(/\W/); 这将匹配包括空格在内的所有特殊字符。 If you are looking for special characters, then try \W var pattern = new RegExp(/\W/); This will match all special characters including space. -
使用bash regexp将文件的内容插入另一个文件(Using bash regexp to insert the contents of a file into another)[2023-02-27]
因为你在双引号中使用$() ,所以shell正在解析cat \1 ,剥离反斜杠并尝试运行cat 1以将其输出作为参数的一部分传递给sed。 Sed有一个用于读取文件的命令( r ),但文件名必须是文字的,并且不能是以前的sed命令的结果(至少在标准的sed中,也许某些实现提供了这种能力)。 sed确实是错误的工具。 你可以做一个awk解决方案,但它会很脆弱。 这是一个可能的perl解决方案(警告:脆弱): perl -ne 'if( $_ =~ /\$\.getScript\('"'(.*)'"'\)/ ) ... -
.*被称为贪婪点匹配子模式,它匹配" ,和"任何字符, 包括换行符 。 因此,限制贪婪的最佳技巧是使用一个否定的字符类[^"]来匹配任何字符但是" (如果引用的字符串中没有引号): '\[assembly: AssemblyVersion\("([^"]*)"\)\]' ^^^^^ 演示 或 - 如果引用的字符串中应该没有(和) : '\[assembly: AssemblyVersion\("([^()]*)"\)\]' ...