首页 \ 问答 \ 等待httpclient(Awaiting httpclient)

等待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
更新时间:2023-09-29 10:09

最满意答案

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 in re 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 ...
  • 只需删除read line周围的[] - 它们应该用于执行测试(文件存在,字符串为空等)。 Just remove the [] around read line - they should be used to perform tests (file exists, string is empty etc.).
  • 它不是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 ...
  • 改变这一行: $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 ...
  • 修改你的: \s*${varName}(\s?[\s\=]\s?).+\s*;{0,1} Modifying yours: \s*${varName}(\s?[\s\=]\s?).+\s*;{0,1}
  • 如果您正在寻找特殊字符,请尝试\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.
  • 因为你在双引号中使用$() ,所以shell正在解析cat \1 ,剥离反斜杠并尝试运行cat 1以将其输出作为参数的一部分传递给sed。 Sed有一个用于读取文件的命令( r ),但文件名必须是文字的,并且不能是以前的sed命令的结果(至少在标准的sed中,也许某些实现提供了这种能力)。 sed确实是错误的工具。 你可以做一个awk解决方案,但它会很脆弱。 这是一个可能的perl解决方案(警告:脆弱): perl -ne 'if( $_ =~ /\$\.getScript\('"'(.*)'"'\)/ ) ...
  • .*被称为贪婪点匹配子模式,它匹配" ,和"任何字符, 包括换行符 。 因此,限制贪婪的最佳技巧是使用一个否定的字符类[^"]来匹配任何字符但是" (如果引用的字符串中没有引号): '\[assembly: AssemblyVersion\("([^"]*)"\)\]' ^^^^^ 演示 或 - 如果引用的字符串中应该没有(和) : '\[assembly: AssemblyVersion\("([^()]*)"\)\]' ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。