使用等待版本的readasstringasync() [英] Using await version of readasstringasync()

查看:331
本文介绍了使用等待版本的readasstringasync()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我可以在这里获得一些帮助吗?我正在尝试使用此网站上的爆米花时间API,所以我在visual studio中安装了所需的软件包但是当我粘贴代码时它显示错误说

错误CS4033,'await'操作符可以只能在异步方法中使用。考虑使用'async'修饰符标记此方法并将其返回类型更改为'Task'

拜托,您能为我检查并更正它,我做非常感谢任何帮助!

我从这里开始使用API​​,https://popcornofficial.docs.apiary.io/#reference/show/pages



我尝试过:



//这是我的代码

Hello, can I get a little help here? I am trying to use popcorn time API from this site so I have installed the required packages in visual studio but when I paste the code it shows an error saying
"Error CS4033, The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'"
please, can you check it for me and correct it, I do really appreciate any help!
and I have taken API from here, https://popcornofficial.docs.apiary.io/#reference/show/pages

What I have tried:

//this is my code

private void button1_Click(object sender, EventArgs e)
{
    System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
    var baseAddress = new Uri("https://tv-v2.api-fetch.website/");
    using (var httpClient = new HttpClient { BaseAddress = baseAddress })
    {
        using (var response = await httpClient.GetAsync("undefined"))
        {
            string responseData = await response.Content.ReadAsStringAsync();
        }
    }
}

推荐答案

检查过去asnswer:修复:'await'运算符只能是在异步方法中使用。考虑使用'async'修饰符标记此方法并将其返回类型更改为'Task< System.Web.Mvc.ActionResult>'? [ ^ ]
Check past asnswer: Fix for : The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task<System.Web.Mvc.ActionResult>' ?[^]


试试这个并阅读你复制和粘贴的内容:



Try this and read up on things you copy&paste:

private async void button1_Click(object sender, EventArgs e)
{
    System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
    var baseAddress = new Uri("https://tv-v2.api-fetch.website/");
    using (var httpClient = new HttpClient { BaseAddress = baseAddress })
    {
        using (var response = await httpClient.GetAsync("undefined"))
        {
            string responseData = await response.Content.ReadAsStringAsync();
        }
    }
}


对我来说看起来像普通的JSON:

JSON - 维基百科 [ ^ ]



类似于XML的数据格式。没有错 - 你必须向网站的作者询问其含义(其模式定义)......
Looks like plain JSON to me:
JSON - Wikipedia[^]

Its similar data format like XML. Nothing wrong with that - you have to ask the authors of the site about the meaning (its schema definition)...


这篇关于使用等待版本的readasstringasync()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆