Jump to content
  • Sign Up

Random bad request error when starting to get data from the API


Thiraz.4279

Recommended Posts

My web app used to work fine for weeks and suddently I get bad request errors when getting data from the API.

 

I usually get an error between the second and the 5th pages requested. It happens on the production server and in my home development environment.

 

Here is the website:

http://gw2priceanalyzer.azurewebsites.net/

 

Here is the code to get the data:

 

public static IQueryable ListItemDetails { get; private set; }

public static IQueryable ListPriceDetails { get; private set; }

 

public static async Task GetData()

{

using (var webClient = new WebClient())

{

var tempPrices = new List();

var tempItems = new List();

var jsonData = await webClient.DownloadStringTaskAsync("https://api.guildwars2.com/v2/commerce/prices/");

var listItems = JsonConvert.DeserializeObject>(jsonData);

var totalPagesCount = listItems.Count / 200;

for (var pageCount = 0; pageCount <= totalPagesCount; pageCount++)

{

jsonData = await webClient.DownloadStringTaskAsync($"https://api.guildwars2.com/v2/commerce/prices?page={pageCount}&page_size=200");

tempPrices.AddRange(JsonConvert.DeserializeObject>(jsonData));

jsonData = await webClient.DownloadStringTaskAsync($"https://api.guildwars2.com/v2/items?page={pageCount}&page_size=200");

tempItems.AddRange(JsonConvert.DeserializeObject>(jsonData));

}

ListPriceDetails = tempPrices.AsQueryable();

ListItemDetails = tempItems.AsQueryable();

}

return true;

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...