1

I am trying to use the BART's API to get a response using RestSharp. Here is what I have so far:

        var client = new RestSharp.RestClient("http://api.bart.gov/");
        var request = new RestRequest ("");
        request.AddParameter ("cmd", "stns");
        request.AddParameter ("key", "MW9S-E7SL-26DU-VV8V");
        IRestResponse response = client.Execute (request);

This should get a list of all Bart Stations. The stns parameter says to get all stations and the key is the API key.

However, when I try to print it out

Console.WriteLine (response.Content);

I get some weird document that says how to use BART API followed with some type of error that says

Unknown Server (64-126)

Any ideas? I suspect it might be a simple error with how I have the Parameters set up or the way the client is set up.

1
  • 1
    http://api.bart.gov/ Are you sure this shouldn't be http://api.bart.gov/api/stn.aspx ? See the bottom of your linked documentation: Usage http://api.bart.gov/api/stn.aspx?cmd=stns&key=MW9S-E7SL-26DU-VV8V Commented Jul 27, 2015 at 2:40

1 Answer 1

3

Based on their sample, the url to get a list of stations is http://api.bart.gov/api/stn.aspx?cmd=stns&key=MW9S-E7SL-26DU-VV8V

If so, you want your request to look like:

var client = new RestSharp.RestClient("http://api.bart.gov/");
var request = new RestRequest ("/api/stn.aspx");
request.AddParameter ("cmd", "stns");
request.AddParameter ("key", "MW9S-E7SL-26DU-VV8V");
IRestResponse response = client.Execute (request);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.