Click here to Skip to main content
15,913,115 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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();
        }
    }
}
Posted
Updated 6-Feb-18 19:47pm
v2

 
Share this answer
 
Comments
Member 13664349 6-Feb-18 12:58pm    
what does it mean "You Need to include "async" identifier in your method signature" I saw it before but I didn't understand it. by the way I am native in English, hope you got my situation
Maciej Los 6-Feb-18 13:04pm    
Follow the link provided there. An MSDN documentation is quite clear. ;) In other words, you have to add async keyword.
Member 13664349 6-Feb-18 13:50pm    
Thanks a lot, one last question, after finishing running this code responseData equals "", but when u visit the link "https://tv-v2.api-fetch.website/movie/tt1457767" you can notice it's rich of content, what is wrong?

private async void button1_Click(object sender, EventArgs e)
{
var baseAddress = new Uri("https://tv-v2.api-fetch.website/movie/tt1457767");
using (var httpClient = new HttpClient { BaseAddress = baseAddress })
{
using (var response = await httpClient.GetAsync("undefined"))
{
string responseData = await response.Content.ReadAsStringAsync();
}
}
}
Member 14539824 15-Jan-20 9:07am    
merhaba
Member 14539824 15-Jan-20 9:07am    
iyi senden
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();
        }
    }
}
 
Share this answer
 
Comments
Member 13664349 6-Feb-18 13:28pm    
Thanks a lot, one last question, after finishing running this code responseData equals "", but when u visit the link "https://tv-v2.api-fetch.website/movie/tt1457767" you can notice it's rich of content, what is wrong?

private async void button1_Click(object sender, EventArgs e)
{
var baseAddress = new Uri("https://tv-v2.api-fetch.website/movie/tt1457767");
using (var httpClient = new HttpClient { BaseAddress = baseAddress })
{
using (var response = await httpClient.GetAsync("undefined"))
{
string responseData = await response.Content.ReadAsStringAsync();
}
}
}
Member 14539824 15-Jan-20 9:07am    
selam
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)...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900