Nicholas Sloan
Nicholas Sloan

Reputation: 3

Adding parameters to GET API call

Good evening!

This is my first time posting here and have looked throughout the web to try and discover how to do this. Essentially I am looking to add parameters within my GET API call.

This is my code so far

public string TestingRequest(string uri, string apiKey)
    {
        try
        {

            using (WebClient wc = new WebClient())
            {


                wc.Credentials = new NetworkCredential(apiKey, "MYSPORTSFEEDS");
                wc.UseDefaultCredentials = true;
                wc.QueryString.Add("I don't know what goes here...");
                string HtmlResult = wc.DownloadString(uri);
                return HtmlResult;
            }
        }

        catch
        {
            return "";
        }
    }

I am wanting to return the 2017 season. The website I am using lists

season={season-identifier}
(optional) a specific season, identified by concatenating

(season start year) + "-" + (season end year) + "-" + either "regular" or "playoff", depending on the season's type

An example: "2017-regular"

EDIT: I added wc.QueryString.Add("season", "2017-regular"); per a comment below. I can't tell if it works or not. I set a break point on wc.DownloadString(uri); and when it hits that code, it bounces down to my catch block. I would think that would mean the program wasn't able to locate the uri

Upvotes: 0

Views: 1673

Answers (1)

Meow_ly
Meow_ly

Reputation: 156

Try using the the add(String,String) method:

wc.QueryString.Add("season","2017-regular");

The first value is the parameter name, the second is the value of that parameter. Name would be Season, and the value would be the season that you're targeting.

Upvotes: 1

Related Questions